hdu 1028 Ignatius and the Princess III

Posted phlsheji

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 1028 Ignatius and the Princess III相关的知识,希望对你有一定的参考价值。

题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=1028

思路一:和hdu1398 1284一样

思路二:參考自http://www.cnblogs.com/xingluzhe/archive/2009/09/01/1557844.html


code1

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
    int dp[122];
    int n,i,j;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(i=1;i<=122;i++)
    {
        for(j=i;j<=122;j++)
        {
            dp[j]+=dp[j-i];
        }
    }
    while(scanf("%d",&n)==1)
    {
        printf("%d\\n",dp[n]);
    }
    return 0;
}



code 2:

#include<cstdio>
#include<iostream>
typedef __int64 ll;

using namespace std;

ll dp[125][125];

int main()
{
    ll n,i,j;
    while(scanf("%d",&n)==1)
    {
        for(i=0;i<122;i++)
        {
            dp[i][1]=1;
            dp[1][i]=1;
        }
        for(i=2;i<122;i++)
        {
            for(j=2;j<122;j++)
            {
                if(j>i) dp[i][j]=dp[i][i];
                if(j==i) dp[i][j]=dp[i][j-1]+1;
                if(j<i) dp[i][j]=dp[i][j-1]+dp[i-j][j];
            }
        }
        printf("%I64d\\n",dp[n][n]);
    }
    return 0;
}


以上是关于hdu 1028 Ignatius and the Princess III的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1028 Ignatius and the Princess III (动态规划)

hdu 1028 Ignatius and the Princess III

HDU 1028: Ignatius and the Princess III

hdu 1028 Ignatius and the Princess III 母函数

HDU1028 Ignatius and the Princess III 母函数

HDU 1028 Ignatius and the Princess III(生成函数)