HDU1028 Ignatius and the Princess III

阅读: 评论:0

HDU1028 Ignatius and the Princess III

HDU1028 Ignatius and the Princess III

《ACM程序设计》期末上机考试安排
Ignatius and the Princess III


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16565    Accepted Submission(s): 11675




Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.


"The second problem is, given an positive integer N, we define an equation like this:
  N=a[1]+a[2]+a[3]+...+a[m];
  a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
  4 = 4;
  4 = 3 + 1;
  4 = 2 + 2;
  4 = 2 + 1 + 1;
  4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
 


Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
 


Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
 


Sample Input
4
10
20
 


Sample Output
5
42
627
 


Author
Ignatius.L

 

          题意:把一个数因式分解,点到顺序的不算,比如5=1+4和5=4+1就算是一种方式

              这个题目是个简单的母函数的……

  方法一:  题解:等于在式子的‘+’号后面一次加上一个数字形成新的,而且要求加上的这个数字是当前式子里面最大的,这样就不会重复
如:
分解的那个整数 
1  2   3   4   5   6
+1 1  


1+1  1+1+1 1+1+1+1
1+1+1+1+1
1+1+1+1+1+1




+2 2
1+2  1+1+2 1+1+1+2
1+1+1+1+2
2+2
1+2+2  1+1+2+2
2+2+2




+3 3
1+3
1+1+3
1+1+1+3
2+3
1+2+3
3+3




+4 4
1+4  1+1+4
2+4






+5 5
1+5


+6 6


因式分解的方式数:1    2   3   5   7   11


比如+1的时候,6就从5里面找,因为5+1=6,+2的时候6就从4里面找,+3的时候就从3里面找,这么算下去,到+6的时候,6本身也算进来,所以就等于从0里面加一个


#include<stdio.h>
int main()
{int i,j,k,l;int a[125]={1};for(i=1;i<121;i++)for(j=i;j<121;j++)a[j]=a[j]+a[j-i];while(~scanf("%d",&k))printf("%dn",a[k]);return 0;
}
方法二:

   

#include<stdio.h>
#include<string.h> 
int main()
{int i,j,k,l,n;int a1[201],a2[201];while(~scanf("%d",&n)){memset(a1,0,sizeof(a1));memset(a2,0,sizeof(a2));a2[0]=1;for(i=1;i<=n;i++){for(j=0;j<=n;j++)for(k=0;j+k*i<=n;k++)a1[j+k*i]+=a2[j];  //方括号内是指数,// a1[]代表将要去乘的系数, for(j=0;j<=n;j++)  //a2[]即是代表已乘好的系数, {a2[j]=a1[j];   // 对系数进行赋值…… a1[j]=0; }} printf("%dn",a2[n]);}return 0;
}



本文发布于:2024-01-29 12:49:37,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170650378015398.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Ignatius   III   Princess
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23