HDU 1028Ignatius and the Princess III(母函数简单题)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
"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
Output
Sample Input
Sample Output
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
int N;
int c1[],c2[];
while(cin>>N) {
int i,j,k;
for(i=; i<=N; i++) { //初始化第一个表达式的系数
c1[i]=;
c2[i]=;
}
for(i=; i<=N; i++) {
//从第二个表达式开始,因为有无限制个,所以有n个表达式
for(j=; j<=N; j++) {
//从累乘的表达式后的一个表达式第一个到最后一个
for(k=; k+j<=N; k+=i) {
//k为第j个变量的指数,第i个表达式每次累加i
c2[j+k]+=c1[j];
}
}
for(j=; j<=N; j++) {
//滚动数组算完一个表达式后更新一次
c1[j]=c2[j];
c2[j]=;
}
}
printf("%d\n",c1[N]);
}
return ;
}
HDU 1028Ignatius and the Princess III(母函数简单题)的更多相关文章
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Sample Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Ignatius and the Princess III(母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU-1028-Ignatius and the Princess III(母函数)
链接: https://vjudge.net/problem/HDU-1028 题意: "Well, it seems the first problem is too easy. I wi ...
- HDU1028Ignatius and the Princess III(母函数)
http://acm.hdu.edu.cn/showproblem.php?pid=1028 母函数: 例1:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? 如何解决这 ...
- HDU1028Ignatius and the Princess III母函数入门
这个题也能够用递归加记忆化搜索来A,只是因为这题比較简单,所以用来做母函数的入门题比較合适 以展开后的x4为例,其系数为4,即4拆分成1.2.3之和的拆分数为4: 即 :4=1+1+1+1=1+1+2 ...
- HDU 1028 HDU Ignatius and the Princess III
简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp ...
- HDU 5776 sum( 鸽巢定理简单题 )
链接:传送门 题意:给一个长为 n 的串,问是否有子串的和是 m 的倍数. 思路:典型鸽巢定理的应用,但是这里 n,m 的大小关系是不确定的,如果 n >= m 根据定理可以很简单的判定是一定有 ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- MapReduce shuffle阶段详解
在Mapreduce中,Shuffle过程是Mapreduce的核心,它分布在Mapreduce的map阶段和reduce阶段,共可分为6个详细的阶段: 1).Collect阶段:将MapTask的结 ...
- 小课堂week14 Google软件测试之道
读<Google软件测试之道> 在IT领域,Google是一面旗帜,是一家非常善于思考善于尝试的公司.随着面临挑战的不断增大,传统的测试开展方式也越来越力不从心,这本书讲述的就是一次完整的 ...
- swift 2
... ..< func a(inout a) //by ref use &xx Parameters passed to functions are constants by de ...
- LaTex中让页码从正文开始编号
在正文和目录之前这样设置即可 \setcounter{page}{}
- 有关GIT
今天上班,发现没什么事情. 就看了一些博客,发现有个不错的东西,分享一下. 参考:http://www.liaoxuefeng.com/wiki/0013739516305929606dd183612 ...
- Ubuntu无值守安装mysql
1. 使用apt-get -d install 命令下载安装包, 其中-d表示下载不安装. 下载后的deb包放在/var/cache/apt/archives目录 2. 使用dpkg-preconfi ...
- ASP.NET分页
[代码][C#]代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- [转]理解与使用Javascript中的回调函数
在Javascript中,函数是第一类对象,这意味着函数可以像对象一样按照第一类管理被使用.既然函数实际上是对象:它们能被“存储”在变量中,能作为函数参数被传递,能在函数中被创建,能从函数中返回. 因 ...
- Python实现SVM(支持向量机)
Python实现SVM(支持向量机) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=>end ...
- UIAlertControl swift
let alertController = UIAlertController(title: "开始!", message: "游戏就要开始,你准备好了吗?", ...