HDU1028 Ignatius and the Princess III 【母函数模板题】
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!"
4
10
20
5
42
627
整数拆分无限取,跟着包子做的题,就当做模板来用吧。
#include <stdio.h>
#define maxn 122 int c1[maxn], c2[maxn]; int main()
{
int n, i, j, k;
while(scanf("%d", &n) != EOF){
for(i = 0; i <= n; ++i){
c1[i] = 1; c2[i] = 0;
}
for(i = 2; i <= n; ++i){
for(j = 0; j <= n; ++j)
for(k = j; k <= n; k += i)
c2[k] += c1[j];
for(k = 0; k <= n; ++k){
c1[k] = c2[k]; c2[k] = 0;
}
}
printf("%d\n", c1[n]);
}
return 0;
}
HDU1028 Ignatius and the Princess III 【母函数模板题】的更多相关文章
- 【母函数】hdu1028 Ignatius and the Princess III
大意是给你1个整数n,问你能拆成多少种正整数组合.比如4有5种: 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + 1 + 1; 4 = 1 + 1 + 1 + 1; ...
- 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 ...
- hdu1028 Ignatius and the Princess III(递归、DP)
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 1028Ignatius and the Princess III(母函数简单题)
Ignatius and the Princess III Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)
Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...
- hdu1028 Ignatius and the Princess III
这是道典型的母函数的题目,可以看看我的母函数这一标签上的另一道例题,里面对母函数做了较为详细的总结.这题仅贴上代码: #include"iostream" using namesp ...
- HDU-1028 Ignatius and the Princess III(生成函数)
题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...
随机推荐
- [Everyday Mathematics]20150301
设 $f(x)$ 在 $[-1,1]$ 上有任意阶导数, $f^{(n)}(0)=0$, 其中 $n$ 是任意正整数, 且存在 $C>0$, $$\bex |f^{(n)}(x)|\leq C^ ...
- 7、NFC技术:让Android自动运行程序
用于描述NDEF格式数据的两个重要的类 NdefMessage:描述NDEF格式的信息 NdefRecord:描述NDEF信息的一个信息段 NdefMessage和NdefRecord是Androi ...
- yii框架AR详解
虽 然Yii DAO可以处理事实上任何数据库相关的任务,但很可能我们会花费90%的时间用来编写一些通用的SQL语句来执行CRUD操作(创建,读取,更新和删除). 同时我们也很难维护这些PHP和SQL语 ...
- 数往知来 CSS<十二>
div+css基础 一.外部样式<!--外部样式可以使网页与样式分离,分工处理 1.写网页,主要提供内容,一般都会有固定的结构,具有id等属性的标签包括特定的内容 2.根据结构写样式另存为css ...
- bzoj 3594 [Scoi2014]方伯伯的玉米田(DP+二维BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3594 [题意] 给定一个n个数的序列,有K次将一个区间内的数加1的机会,问最长不下降子 ...
- 最小高度的BST
加深对BST的构建过程及递归思想的理解. /***************************************************** * \file MinimalBST.cpp * ...
- STL map 用法
首先make_pair Pairs C++标准程序库中凡是"必须返回两个值"的函数, 也都会利用pair对象 class pair可以将两个值视为一个单元.容器类别map和mul ...
- Android 订阅-发布者模式-详解
1.概念简述 Android 简称观察者模式, GoF说道:Observer模式的意图是“定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新”. 有 ...
- 20150926kaggle Titanic入门篇excel&python
1 excel数据透视表 这里主要是讲述了一下插入里面的数据透视表常用功能,数据透视表十分方便,比直接筛选还要简单,看数据很直观,这里大力推荐. 2 python&pandas 这里主要是讲述 ...
- home-brew 安装&下载
安装: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&qu ...