注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU 1028 模板题 母函数 Ignatius and the Princess III  

2014-04-16 22:13:51|  分类: 母函数 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

 


Recommend

We have carefully selected several similar problems for
you:  1171 1085 1398 2152 1709 

 

#include <iostream>
#include<fstream>
using namespace std;
int a1[300],a2[300];
int main()
{
int N,i,j,k;
//ifstream cin("aa.txt");
while(cin>>N)
{
for(i=0;i<=N;i++)
{
a1[i]=1;
a2[i]=0;
}
for(i=2;i<=N;i++)
{
for(j=0;j<=N;j++)
{
for(k=0;k+j<=N;k+=i)
{
a2[j+k]+=a1[j];
//cout<<a2[j+k]<<" jj"<<endl;
}
}
for(j=0;j<=N;j++)
{
a1[j]=a2[j];
// cout<<a1[j]<<endl;
a2[j]=0;
}
}
cout<<a1[N]<<endl;
}
return 0;
}



  评论这张
 
阅读(6)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017