a 個の数から b 個の数を重複ありで選び a^b = c 通りの組をつくるときのための処理。辞書順にはならない。出典: https://beta.atcoder.jp/contests/abc100/submissions/2670489
#include <iostream> | |
using namespace std; | |
int main() { | |
int a = 2, b = 3, c = 8; //何通りか事前に計算しておく。 e.g. 2^3=8 | |
for (int i = 0; i < c; i++) { | |
for (int j = 0; j < b; j++) { | |
if((i/(1 << j))%a == 0) cout << "0"; | |
else cout << "1"; //if分岐はaの値に応じて増える | |
} | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment