标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=1028
思路二:參考自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