首页 > 其他分享 >杭电1028

杭电1028

时间:2023-02-06 20:32:32浏览次数:52  
标签:int contains 1028 杭电 integer c2 c1 problem


Ignatius and the Princess III

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

题意:就是计算例如:谁加谁等于4
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
输出5

原理:

杭电1028_i++


第一项:1+x+x^2+x^3…………..

这每一项的意思:

0个1(x^0),1个1(x^1),两个1组成2(x^2),三个1组成3…….n个1组成n(x^n)

第二项:1+x^2+x^4…………..

0个2(x^0),1个2(x^2),两个2(x^4)…………………….

代码:

# include <iostream>

using namespace std;

int main(){

int n,i,j,k;
int c1[130],c2[130];

while(cin>>n){

//对第一项进行赋值
for(i=0;i<=n;i++){
c1[i] = 1;
c2[i] = 0;
}

for(i=2;i<=n;i++){//代表第i项

for(j=0;j<=n;j++){//代表i-1项,其中,满足项的系数j<=n的进行循环,这里不一定是j-1的每一项
for(k=0;k+j<=n;k+=i){//i项符合条件的
c2[j+k]+= c1[j];//i-1项的每一个符合条件的与i项相乘
}
}

for(k=0;k<=n;k++){
c1[k] = c2[k];//把i与i-1项的乘积从临时保存到c2到保存到c1中,等待i+1项与c1的成绩
c2[k] = 0;
}
}
cout<<c1[n]<<endl;
}
return 0;
}


标签:int,contains,1028,杭电,integer,c2,c1,problem
From: https://blog.51cto.com/u_15955675/6040462

相关文章

  • 杭电1085
    ​​这里写链接内容​​HoldingBin-LadenCaptive!TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):13861A......
  • 杭电1398
    SquareCoinsProblemDescriptionPeopleinSilverlandusesquarecoins.Notonlytheyhavesquareshapesbutalsotheirvaluesaresquarenumbers.Coinswithva......
  • 杭电2073
    ​​http://acm.hdu.edu.cn/showproblem.php?pid=2073​​无限的路ProblemDescription甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直......
  • 杭电2095(find your present (2))
    ​​这里写链接内容​​>引用块内容ProblemDescriptionInthenewyearparty,everybodywillgeta“specialpresent”.Nowit’syourturntogetyourspecialpre......
  • 整除的为数 杭电2099
    [1.(​​http://acm.hdu.edu.cn/showproblem.php?pid=2099%20%20%E9%97%AE%E9%A2%98%E9%93%BE%E6%8E%A5​​)]​​``这里写代码片​#include......
  • <Web Navigation> stack-POJ1028
    WebNavigationTimeLimit: 1000MS MemoryLimit: 10000KTotalSubmissions: 41995 Accepted: 18687DescriptionStandardwebbrowserscontainf......
  • 5个千兆网口,将有什么样高速网络传输体验?——米尔MYD-J1028X开发板实测分享
    本篇测评由电子工程世界的优秀测评者“HonestQiao”提供。此次的板卡测试,是米尔MYD-J1028X开发板的高速网络数据传输测试体验。01本次测试的主角米尔MYD-J1028X开发板提供......
  • 5个千兆网口,将有什么样高速网络传输体验?——米尔MYD-J1028X开发板实测分享
    本篇测评由电子工程世界的优秀测评者“HonestQiao”提供。此次的板卡测试,是米尔MYD-J1028X开发板的高速网络数据传输测试体验。  01本次测试的主角米尔MYD-J1028X......
  • 2022 年杭电多校第六场 Multiply 2 Divide 2
    2022年杭电多校第六场Multiply2Divide2题意:BXY的序列\(a\)长度为\(n\)\((1\leqn\leq10^5,1\leqa_i\leq10^5)\)对于每个操作,他选择一个数字\(a_i(1\leqi\leqn......
  • ACdream 1028 Path
    DescriptionCheckifthereexistsapathoflength ll inthegiventreewithweightassignedtoeachedges.InputThefirstlinecontainstwoin......