0
点赞
收藏
分享

微信扫一扫

HDOJ 1028   Ignatius and the Pri…


题目:​​http://acm.hdu.edu.cn/showproblem.php?pid=1028​​


简单的整数拆分问题,题解分析请见:​​http://blog.sina.com.cn/s/blog_9635e5ef01016vyn.html​​

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 130
int n[N][N];
void init(){
int i,j;
for(i=0;i<N;i++)
n[i][1]=n[1][i]=1;
for(i=2;i<N;i++){
for(j=2;j<N;j++){
if(i>j)
n[i][j]=n[i][j-1]+n[i-j][j];
else if(i==j)
n[i][j]=1+n[i][j-1];
else
n[i][j]=n[i][i];
}
}
}
int main()
{
int a;
init();
while(scanf("%d", &a) != EOF)
printf("%d\n", n[a][a]);
return 0;
}

举报

相关推荐

0 条评论