题解:
背包
每一个1<<i都是无限量
代码:
#include<bits/stdc++.h> using namespace std; const int N=1000005,M=1e9; int n,dp[N]; int main() { scanf("%d",&n); dp[0]=1; for (int i=0;i<20;i++) for (int j=1<<i;j<=n;j++) (dp[j]+=dp[j-(1<<i)])%=M; printf("%d",dp[n]); }
题解:
背包
每一个1<<i都是无限量
代码:
#include<bits/stdc++.h> using namespace std; const int N=1000005,M=1e9; int n,dp[N]; int main() { scanf("%d",&n); dp[0]=1; for (int i=0;i<20;i++) for (int j=1<<i;j<=n;j++) (dp[j]+=dp[j-(1<<i)])%=M; printf("%d",dp[n]); }