• 整数划分 dp+母函数


    dp:

    #include<bits/stdc++.h>
    using namespace std;
    typedef unsigned int ui;
    typedef long long ll;
    typedef unsigned long long ull;
    #define pf printf
    #define mem(a,b) memset(a,b,sizeof(a))
    #define prime1 1e9+7
    #define prime2 1e9+9
    #define pi 3.14159265
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define scand(x) scanf("%llf",&x) 
    #define f(i,a,b) for(int i=a;i<=b;i++)
    #define scan(a) scanf("%d",&a)
    #define mp(a,b) make_pair((a),(b))
    #define P pair<int,int>
    #define dbg(args) cout<<#args<<":"<<args<<endl;
    #define inf 0x7ffffff
    inline int read(){
        int ans=0,w=1;
        char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
        while(isdigit(ch))ans=(ans<<3)+(ans<<1)+ch-'0',ch=getchar();
        return ans*w;
    }
    int n,m,t;
    const int maxn=150;
    const ll mod=10000;
    ll dp[maxn+1][maxn+1];
    int main()
    {
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
        std::ios::sync_with_stdio(false);
        f(i,1,maxn)
            f(j,1,maxn){
                if(i==1||j==1)dp[i][j]=1;
                else if(i==j)dp[i][j]=dp[i][j-1]+1;
                else if(i<j)dp[i][j]=dp[i][i];
                else dp[i][j]=dp[i-j][j]+dp[i][j-1];
            }
        while(scanf("%d",&n)!=EOF){
            pf("%lld
    ",dp[n][n]);
        }
    }

    母函数:

    #include<bits/stdc++.h>
    using namespace std;
    typedef unsigned int ui;
    typedef long long ll;
    typedef unsigned long long ull;
    #define pf printf
    #define mem(a,b) memset(a,b,sizeof(a))
    #define prime1 1e9+7
    #define prime2 1e9+9
    #define pi 3.14159265
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define scand(x) scanf("%llf",&x) 
    #define f(i,a,b) for(int i=a;i<=b;i++)
    #define scan(a) scanf("%d",&a)
    #define mp(a,b) make_pair((a),(b))
    #define P pair<int,int>
    #define dbg(args) cout<<#args<<":"<<args<<endl;
    #define inf 0x7ffffff
    inline int read(){
        int ans=0,w=1;
        char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
        while(isdigit(ch))ans=(ans<<3)+(ans<<1)+ch-'0',ch=getchar();
        return ans*w;
    }
    int n,m,t;
    const int maxn=150;
    const ll mod=10000;
    ll c1[maxn],c2[maxn];
    int main()
    {
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
        std::ios::sync_with_stdio(false);
        f(i,0,maxn-1)
        {
            c1[i]=1,c2[i]=0;
        }
        for(int k=2;k<maxn;k++){
            for(int i=0;i<maxn;i++){
                for(int j=0;j+i<maxn;j+=k){
                    c2[i+j]+=c1[i];
                }
            }
            for(int i=0;i<maxn;i++){
                c1[i]=c2[i],c2[i]=0;
            }
        }
        while(scanf("%d",&n)!=EOF){
            pf("%lld
    ",c1[n]);
        }
    }
  • 相关阅读:
    《超越自己》--刘墉
    《菊与刀》--[美]鲁思·本尼迪克特(Ruth Benedict)
    《暧昧的日本人》--李兆忠
    《女性的选择》--[日]今野由梨
    《懂得低头,才能出头》--李艳
    原来还有这样的记词方法_Java版记不规则动词_博主推荐
    《永不止步》--[奥]力克胡哲
    C#面向服务WebService从入门到精通
    C# Windows服务开发从入门到精通
    sql server递归查询
  • 原文地址:https://www.cnblogs.com/randy-lo/p/13053610.html
Copyright © 2020-2023  润新知