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 ...
随机推荐
- Luogu 3616 富金森林公园
刚看到此题的时候:sb分块??? Rorshach dalao甩手一句看题 于是回去看题……果然是题读错了…… [思路] 对权值离散化后(要先读入所有输入里的权值一起离散化……所以一共有4e4个数据( ...
- Mybatis——逆向工程
一.引入依赖 mybatis-generator-core-1.3.2.jar 二.基于XML的配置 <?xml version="1.0" encoding="U ...
- 【Azure Active Directory】单一登录 (SAML 协议)
Azure Active Directory 支持 SAML 2.0 Web 浏览器单一登录 (SSO) 配置文件. 若要请求 Azure Active Directory 对用户进行身份验证时,云服 ...
- redis系列:基于redis的分布式锁
一.介绍 这篇博文讲介绍如何一步步构建一个基于Redis的分布式锁.会从最原始的版本开始,然后根据问题进行调整,最后完成一个较为合理的分布式锁. 本篇文章会将分布式锁的实现分为两部分,一个是单机环境, ...
- netty使用以及聊天小程序
<从零开始搭建游戏服务器>Netty导入创建Socket服务器 Netty入门教程 Netty 聊天小程序
- [转]B+Tree图解
一, M阶B+树的定义(M阶是指一个节点最多能拥有的孩子数,M>2): 图1.1 3阶B+树 (1)根结点只有1个,分支数量范围[2,m]. (2)除根以外的非叶子结点,每个结点包含分支数 ...
- angular ng-content
<p> child works! </p> <ng-content></ng-content> <app-child> 父组件投影 < ...
- angular 路由传参
第一种:<a [routerLink]="['/product']" [queryParams]="{id: 1}">商品详情</a> ...
- (c++11)随机数------c++程序设计原理与实践(进阶篇)
随机数既是一个实用工具,也是一个数学问题,它高度复杂,这与它在现实世界中的重要性是相匹配的.在此我们只讨论随机数哦最基本的内容,这些内容可用于简单的测试和仿真.在<random>中,标准库 ...
- 6w4:第六周程序填空题1
描述 下面程序的输出结果是: A::Fun C::Do 请填空: #include <iostream> using namespace std; class A { private: i ...