AcWing 3382. 整数拆分
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
const int M = 25;
int t, n, m, k, l, r, op, x, y;
int f[N];
int g[M];
bool flag;
int mod = 1e9;
void solve() {
g[0] = 1;
for (int i = 1; i < M; i++) {
g[i] = g[i - 1] << 1;
}
cin >> n;
f[0] = 1;
for (int i = 0 ; i < M; i++) {
for (int j = g[i]; j <= n; j++) {
f[j] = (f[j] + f[j - g[i]]) % mod;
}
}
cout << f[n];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}