Created
September 20, 2022 12:55
-
-
Save pithesun/304b5b4479d620df0a5dd397277750fc to your computer and use it in GitHub Desktop.
비트마스킹을 이용한 경우의 수
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
const int n = 4; | |
int main(){ | |
string a[n] = {"사과", "딸기", "포도", "배"}; | |
/* 경우의 수 16개 출력하기 */ | |
for(int i=0; i < (1 << n); i++){ | |
string ret = ""; | |
for(int j=0; j < n; j++){ | |
if(i & (1 << j)){ // 비트가 켜져있는지 확인 | |
ret += (a[j] + " "); | |
} | |
} | |
cout << i << " " << ret << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment