当前位置:网站首页>(counting class +dp) acwing 900 Integer partition

(counting class +dp) acwing 900 Integer partition

2022-06-11 23:35:00 Age worry

900. Integer partition

Topic link https://www.acwing.com/problem/content/902/
subject :
 Insert picture description here
Method :f[i][j] It means that 1~i To piece together j.f[i][j]=f[i-1][j]+f[i][j-i]


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
const int mod=1e9+7;
int f[1010][1010];
//f[i][j]=f[i-1][j]+f[i][j-i];
int main(){
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) f[i][0]=1;
    for(int i=1;i<=n;i++){
    
        for(int j=1;j<=n;j++){
    
            if(j>=i)
            f[i][j]=(f[i-1][j]+f[i][j-i])%mod;
            else
            f[i][j]=f[i-1][j];
        }
            
    }
    cout<<f[n][n];
    return 0;
}


原网站

版权声明
本文为[Age worry]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011607108404.html