Ignatius and the Princess III 1028 (母函数)
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15971 Accepted Submission(s): 11266
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
//母函数公式为:g(x)=(1+x+x^2+x^3+x^4+......)*(1+x^2+x^4+x^6+......)*(1+x^3+x^6+x^9+......)*......
#include<stdio.h>
int a[1010],b[1010];
int main(){
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<=n;i++)
{
a[i]=1;
b[i]=0;
}
for(i=2;i<=n;i++)
{
for(j=0;j<=n;j++)
{
for(k=0;k+j<=n;k+=i)
{
b[k+j]+=a[j];
}
}
for(j=0;j<=n;j++)
{
a[j]=b[j];
b[j]=0;
}
}
printf("%d\n",a[n]);
}
return 0;
}
//拓展一下,下面的这个是母函数公式为g(x)=(1+x)(1+x^2)(1+x^3)......(不能保证是否正确,因为没有相应的题)
#include<stdio.h>
int a[1010],b[1010];
int main(){
int n,i,j,k,t;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<=n;i++)
{
a[i]=1;
b[i]=0;
}
t=3;
for(i=3;i<=n;i++)
{
for(j=0;j<=t;j++)
{
for(k=0;k+j<=n;k+=i)
{
b[k+j]+=a[j];
}
}
t+=i;
for(j=0;j<=n;j++)
{
a[j]=b[j];
b[j]=0;
}
}
printf("%d\n",a[n]);
}
return 0;
}
相关文章
- Java实现 LeetCode 793 阶乘函数后K个零 (分析)
- 第二十六节,Python内置函数
- 从零入门 Serverless | 函数计算的可观测性
- The nodes should be added to the underlying vendor clusterware before adding them to the CRS cluster
- ThinkPHP中:使用递归写node_merge()函数
- [Angular2 Router] Optional Route Query Parameters - The queryParams Directive and the Query Parameters Observable
- The CPU Costing Model: A Few Thoughts Part IV (Map of the Problematique)
- SAP ABAP 解析 excel 文件的函数 TEXT_CONVERT_XLS_TO_SAP 单步执行分析
- Python编程语言学习:在根目录的py文件内调用某叶目录文件内的包/库或者函数(常用在GUI编程)之详细攻略
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- ML之分类预测:分类预测评估指标之AUC计算的的两种函数具体代码案例实现
- 成功解决MSB8020 The build tools for v141 (Platform Toolset = ‘v141‘) cannot be found. To build using the
- Qt 字符串截取常用函数
- 【MATLAB】求复合函数
- cdf(Cumulative Distribution Function)累积分布函数==>小于等于当前数据值的所有数据的概率分布
- The difference between the request time and the current time is too large.阿里云oss上传图片报错
- 魔戒 (The Lord of the Rings,又译《指环王》)
- strchr函数的实现而不是使用
- D3DXQuaternionBaryCentric 函数
- git push报错 fatal: The current branch master has no upstream branch. To push the current
- (六)Jenkins部署项目报错The username you provided is not allowed to use the text-based Tomcat Manager (error
- SDL_UpdateRect函数