• 整数划分问题


    http://www.51nod.com/Challenge/Problem.html#!#problemId=1201

    将整数划分为不同的整数的划分方法

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define INF 0x3f3f3f3f
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pqueue priority_queue
    #define NEW(a,b) memset(a,b,sizeof(a))
    const double pi=4.0*atan(1.0);
    const double e=exp(1.0);
    const int maxn=3e6+8;
    typedef long long LL;
    typedef unsigned long long ULL;
    //typedef pair<LL,LL> P;
    const LL mod=1e9+7;
    const ULL base=1e7+7;
    using namespace std;
    int dp[50008][408];
    int main(){
        int n;
        scanf("%d",&n);
        dp[1][1]=1;
        for(int i=2;i<=n;i++){
            for(int j=1;j*(j+1)/2<=i;j++){
                dp[i][j]=(dp[i-j][j]+dp[i-j][j-1]);
                dp[i][j]%=mod;
            }
        }
        LL ans=0;
        for(int j=1;j*(j+1)/2<=n;j++){
            ans+=dp[n][j];
            ans%=mod;
        }
        cout<<ans<<endl;
    }

    http://www.51nod.com/Challenge/Problem.html#!#problemId=1259 

    将整数划分为若干个整数(可以有相同)的方法

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define INF 0x3f3f3f3f
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pqueue priority_queue
    #define NEW(a,b) memset(a,b,sizeof(a))
    const double pi=4.0*atan(1.0);
    const double e=exp(1.0);
    const int maxn=3e6+8;
    typedef long long LL;
    typedef unsigned long long ULL;
    //typedef pair<LL,LL> P;
    const LL mod=1e9+7;
    const ULL base=1e7+7;
    using namespace std;
    LL dp[50008];
    int fiv[50008];
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=1;fiv[i*2-2]<50008;i++){///五边形数
            fiv[i*2-1]=i*(3*i-1)/2;
            fiv[i*2]=i*(3*i+1)/2;
        }
        dp[0]=1;
        dp[1]=1;
        dp[2]=2;
        dp[3]=3;
        dp[4]=5;
        dp[5]=7;
        for(int i=6;i<=n;i++){
            int q=1;
            for(int k=1;fiv[k]<=i;k++){
                dp[i]+=q*dp[i-fiv[k]];
                dp[i]%=mod;
                if(k%2==0){
                    q=-q;
                }
            }
        }
        if(dp[n]<0) dp[n]+=mod;
        cout<<dp[n]<<endl;
    }

     整数划分为2的幂

    http://www.51nod.com/Challenge/Problem.html#!#problemId=1383

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define INF 0x3f3f3f3f
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pqueue priority_queue
    #define NEW(a,b) memset(a,b,sizeof(a))
    const double pi=4.0*atan(1.0);
    const double e=exp(1.0);
    const int maxn=3e6+8;
    typedef long long LL;
    typedef unsigned long long ULL;
    //typedef pair<LL,LL> P;
    const LL mod=1e9+7;
    const ULL base=1e7+7;
    using namespace std;
    LL dp[maxn];
    int main(){
        int n;
        scanf("%d",&n);
        dp[0]=1;
        for(int i=1;i<=n;i++){
            if(i&1){
                dp[i]=dp[i-1];
            }
            else{
                dp[i]=dp[i-1]+dp[i/2];
            }
            dp[i]%=mod;
        }
        if(dp[n]<0) dp[n]+=mod;
        cout<<dp[n]<<endl;
    }
  • 相关阅读:
    RegularExpression 2
    Python __str__() and __repr()__
    RegularExpression 1
    python new kill callback
    Generic Programming v1
    spring的@Transactional注解详细用法
    cmd批量打开网页和关闭网页的批处理代码
    windows批处理中实现延时的办法
    单元测试
    Protocol (网络数据交换规则)
  • 原文地址:https://www.cnblogs.com/Profish/p/11190698.html
Copyright © 2020-2023  润新知