Skip to content

Instantly share code, notes, and snippets.

@pithesun
Created September 20, 2022 12:55
Show Gist options
  • Save pithesun/304b5b4479d620df0a5dd397277750fc to your computer and use it in GitHub Desktop.
Save pithesun/304b5b4479d620df0a5dd397277750fc to your computer and use it in GitHub Desktop.
비트마스킹을 이용한 경우의 수
#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