HDU_1028 Ignatius and the Princess III 【母函数的应用之整数拆分】
题目:
"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!"
InputThe 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.
OutputFor 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
题意分析:
这题是对母函数的另一个应用,整数的拆分。
我们可以把每个数的数值当作母函数经典例题中的砝码的质量。然后把需要凑的总数值当作砝码需要称的质量,这题就比较好理解了。
打表,控制指数在120以内。
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN = 120;
int C1[MAXN+3], C2[MAXN+3]; void solve()
{
int i, j, k;
for(i = 0; i <= MAXN; i++)
{
C1[i] = 1;
C2[i] = 0;
}
for(i = 2; i <= MAXN; i++)
{
for(j = 0; j <= MAXN; j++)
{
for(k = 0; k+j <= MAXN; k+=i)
{
C2[k+j] += C1[j];
}
}
for(j = 0; j <= MAXN; j++)
{
C1[j] = C2[j];
C2[j] = 0;
}
}
} int main()
{
int N;
solve();
while(scanf("%d", &N)!=EOF)
{
printf("%d\n", C1[N]);
}
return 0;
}
HDU_1028 Ignatius and the Princess III 【母函数的应用之整数拆分】的更多相关文章
- 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 母函数
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 ...
- HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDOJ 1028 Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU1028 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(杭电1028)(母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 ...
随机推荐
- Django框架 之 Pagination分页实现
Django框架 之 Pagination分页实现 浏览目录 自定义分页 Django内置分页 一.自定义分页 1.基础版自定义分页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- 7.linux安全基线加固
本文大多截图出自于:http://c.biancheng.net/cpp/shell/ 现在大多数企业都是使用linux作为服务器,不仅是linux是开源系统,更是因为linux比windows更安全 ...
- 利用 Aspose.Words 组件,在不依赖与 Office 组件的情况下把 Word 文件转换成 HTML 代码。
首先利用 Nuget 获取 Aspose.Words.dll public ActionResult AsposeWordsDemo() { string srcFileName = Server.M ...
- 防止SQL注入方法总结
一.参数化SQL 是指在设计与数据库链接并访问数据时,在需要填入数值或数据的地方,使用参数 (Parameter) 来给值,用@来表示参数. 在使用参数化查询的情况下,数据库服务器不会将参数的内容视为 ...
- 一步到位带你入门Selenium
其实,关于这篇文章发布前还是有很多思考的,我是不想发布的,因为关于selenium的文章博客园里面有很多的介绍,写的详细的,也有写的不详细的,那么我的这篇文章的定位是基于selnium从开始到最后的框 ...
- MVC复杂类型的模型绑定
1,属性为引用类型(非集合,非数组) //模型1 public class Contact { public string Name { get; set; } public string Phone ...
- 【2008nmj】Logistic回归二元分类感知器算法.docx
给你一堆样本数据(xi,yi),并标上标签[0,1],让你建立模型(分类感知器二元),对于新给的测试数据进行分类. 要将两种数据分开,这是一个分类问题,建立数学模型,(x,y,z),z指示[0,1], ...
- NAO机器人
NAO机器人是Aldebaran Robotics公司研制的一款人工智能机器人.它拥有着讨人喜欢的外形,并具备有一定程度的人工智能和约一定程度的情感智商并能够和人亲切的互动. 教学研究类/NAO机器人 ...
- .net Stream篇(六)
BufferedStream 目录: 简单介绍一下BufferedStream 如何理解缓冲区? BufferedStream的优势 从BufferedStream 中学习装饰模式 如何理解装饰模式 ...
- 声明函数指针、回调函数、函数对象------c++程序设计基础、编程抽象与算法策略
声明函数指针 #include<iostream> using namespace std; double a(double aa) { return aa; } int main() { ...