• 51nod 1201 整数划分 dp


    基准时间限制:1 秒 空间限制:131072 KB 
     收藏
     关注
    将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2,4} {1,2,3},共4种。由于数据较大,输出Mod 10^9 + 7的结果即可。
     
    Input
    输入1个数N(1 <= N <= 50000)。
    Output
    输出划分的数量Mod 10^9 + 7。
    Input示例
    6
    Output示例
    4

    思路:dp[i][j]表示i分成j个数的方案;

       dp[i][j]=dp[i-j][j]+dp[i-j][j-1];

       一个表示含有1的数目,一个表示不含有1的数目;

       nsqrt(n);

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<bitset>
    #include<set>
    #include<map>
    #include<time.h>
    using namespace std;
    #define LL long long
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=5e4+10,M=1e6+10,inf=1e9+10,MOD=1e9+7;
    const LL INF=1e18+10,mod=1e9+7;
    const double eps=(1e-8),pi=(4*atan(1.0));
    
    int dp[N][500];
    int main()
    {
        dp[0][0]=1;
        for(int i=1;i<=50000;i++)
        {
            for(int j=1;i>=j&&j<=400;j++)
                dp[i][j]=(dp[i-j][j-1]+dp[i-j][j])%mod;
        }
        int n,ans=0;
        scanf("%d",&n);
        for(int i=1;i<=400;i++)
            ans+=dp[n][i],ans%=mod;
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    弱网环境测试点总结
    【CMDB】高级配置
    【CMDB】获取服务器数据
    Centos部属前后端项目
    Centos部署项目
    Django
    nginx反向代理和负载均衡
    nginx的配置
    centos7 安装nginx
    centos7 安装Virtualenv
  • 原文地址:https://www.cnblogs.com/jhz033/p/7616351.html
Copyright © 2020-2023  润新知