首页 > 其他 > 详细

hdu 1028 Ignatius and the Princess III

时间:2016-03-15 20:27:46      阅读:202      评论:0      收藏:0      [点我收藏+]

题目链接: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

原文:http://www.cnblogs.com/bhlsheji/p/5280885.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!