Skip to content

Instantly share code, notes, and snippets.

@aximov
Last active May 9, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aximov/ce6131dc26d8448db94ffffebd9b8d31 to your computer and use it in GitHub Desktop.
Save aximov/ce6131dc26d8448db94ffffebd9b8d31 to your computer and use it in GitHub Desktop.
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