洛谷题号:P2727
参考题解:作者: 罗进瑶 更新时间: 2017-08-04 10:49 https://www.luogu.org/wiki/show?name=%E9%A2%98%E8%A7%A3+P2727
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<string> #include<cassert> #include<map> #include<queue> using namespace std; long long dp[40][40];//dp[i][j]表示长度为i,最多含有j个1的二进制数的个数 int main(){ ios::sync_with_stdio(false); long long n, l, i; cin >> n >> l >> i; for (int i = 0; i <= n; i++)dp[i][0] = dp[0][i] = 1; for (int i = 1; i <= n; i++){ for (int j = 1; j <= l; j++){ dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]; } } long long k = i; for (int i = n; i >= 1; i--){ if (k > dp[i - 1][l]){ cout << "1"; k -= dp[i - 1][l]; l--; } else cout << "0"; } cout << endl; } |