整数划分
https://www.acwing.com/problem/content/description/902/
#include<iostream> #include<algorithm> using namespace std; const int N=1010,mod=1e9+7; int f[N];int n; int main() { cin>>n; f[0]=1; for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) f[j]=(f[j]+f[j-i])%mod; cout<<f[n]<<endl; return 0; }
第二种解法
#include<iostream> #include<algorithm> using namespace std; const int N=1010,mod=1e9+7; int f[N][N];int n; int main() { cin>>n; f[0][0]=1; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) f[i][j]=(f[i-1][j-1]+f[i-j][j])%mod; int res=0; for(int i=1;i<=n;i++) res=(res+f[n][i])%mod; cout<<res<<endl; return 0; }
标签:main,const,int,namespace,计数,1e9,include,dp From: https://www.cnblogs.com/daimazhishen/p/18020778