题解 | #整数拆分#
整数拆分
https://www.nowcoder.com/practice/376537f4609a49d296901db5139639ec
#include<iostream> using namespace std; const int MOD = 1e9; const int N = 1000010; int f[N]; int v[30]; int main(void) { int n; cin >> n; int index = 1; for(int i = 1;i <= n;i *= 2) v[index++] = i; f[0] = 1; for(int i = 1;i < index;i++) { for(int j = v[i];j <= n;j++) { f[j] = (f[j] + f[j - v[i]]) % MOD; } } cout << f[n] << endl; return 0; }