*HDU 1028 母函数
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19589 Accepted Submission(s): 13709
"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 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.
10
20
42
627
/*//整数拆分模板
#include <iostream>
using namespace std;
const int lmax=10000;
//c1是用来存放展开式的系数的,而c2则是用来计算时保存的,
//他是用下标来控制每一项的位置,比如 c2[3] 就是 x^3 的系数。
//用c1保存,然后在计算时用c2来保存变化的值。
int c1[lmax+1],c2[lmax+1];
int main()
{
int n, i, j, k ;
// 计算的方法还是模拟手动运算,一个括号一个括号的计算,
// 从前往后
while ( cin>>n ) {
//对于 1+x+x^2+x^3+ 他们所有的系数都是 1
// 而 c2全部被初始化为0是因为以后要用到 c2[i] += x ;
for ( i=0; i<=n; i++ ) {
c1[i]=1;
c2[i]=0;
}
//第一层循环是一共有 n 个小括号,而刚才已经算过一个了
//所以是从2 到 n
for (i=2; i<=n; i++) {
// 第二层循环是把每一个小括号里面的每一项,都要与前一个
//小括号里面的每一项计算。
for ( j=0; j<=n; j++ )
//第三层小括号是要控制每一项里面 X 增加的比例
// 这就是为什么要用 k+= i ;
for ( k=0; k+j<=n; k+=i ) {
// 合并同类项,他们的系数要加在一起,所以是加法,呵呵。
// 刚开始看的时候就卡在这里了。
c2[ j+k] += c1[ j];
}
// 刷新一下数据,继续下一次计算,就是下一个括号里面的每一项。
for ( j=0; j<=n; j++ ) {
c1[j] = c2[j] ;
c2[j] = 0 ;
}
}
cout<<c1[n]<<endl;
}
return 0;
}
#include<bits\stdc++.h>
using namespace std;
int c1[],c2[];
void solve()
{
for(int i=;i<=;i++)
{
c1[i]=;
c2[i]=;
}
for(int k=;k<=;k++)
{
for(int i=;i<=;i++)
for(int j=;j+i<=;j+=k)
c2[j+i]+=c1[i];
for(int i=;i<=;i++)
{
c1[i]=c2[i];
c2[i]=;
}
}
}
int main()
{
int n;
solve();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",c1[n]);
}
return ;
}
*HDU 1028 母函数的更多相关文章
- hdu 1028 母函数 一个数有几种相加方式
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- 母函数 <普通母函数(HDU - 1028 ) && 指数型母函数(hdu1521)>
给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? ...
- The Balance HDU - 1709 母函数(板子变化)
题意: 现在你被要求用天平和一些砝码来量一剂药.当然,这并不总是可以做到的.所以你应该找出那些不能从范围[1,S]中测量出来的品质.S是所有重量的总质量. 输入一个n,后面有n个数,表示这n个物品的质 ...
- ACM: HDU 1028 Ignatius and the Princess III-DP
HDU 1028 Ignatius and the Princess III Time Limit:1000MS Memory Limit:32768KB 64bit IO Form ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数
HDU - 1028 step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1.临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 , ...
随机推荐
- Gnome_Terminal
快捷键 ctrl shift m 我自定义的快捷键,可以给终端命名 ctrl shift t 新建标签页,并且目录为当前目录 ctrl shift pageup 标签页往前移 ctrl shift p ...
- Xcode静态检查分析代码
Clang静态分析和Instruments来剖析代码有一些不同,Clang更致力于在编译的过程中通过自身的一套判断机制来找出代码中潜在的隐患. 在XCode 3.2之后的版本里,Clang已经被集 ...
- 实现滑动可固定header以及页面刷新
用到的布局:SwiperRefreshLayout,AppBarLayout,ToolBar,CollapsingToolbarLayout,CoordinatorLayout 布局 <?xml ...
- Android中surface,surfaceview,sufaceholder以及surface客户端的关系
这里以照相机camera功能的实现来解释surface,surfaceview,sufaceholder以及surface客户端(本例子中指的是camera)的关系,surface及其client(客 ...
- qtranslate
qtranslate可以帮助用户快速的建立多语言网站平台,qTranslate 插件就是一个功能强大的 WordPress 多语言插件. 它允许用户在配置页添加新的语言.在 URL 结构方面,qTra ...
- 开发日志_Jan.6.2017
Github Jan.2 接到了汤松岩的GUI框架,开始复习和学习C++的使用方法(之前的开发经历主要使用的Java,对C++和QT环境都需要一个再了解). Jan.3 正式开始工作.开始在Ubunt ...
- Spring集成JUnit测试
1.程序中有Junit环境2.导入一个jar包.spring与junit整合jar包 spring-test-3.2.0.RELEASE.jar3.测试代码 @RunWith(SpringJUnit4 ...
- [leetcode] 提醒整理之进制
12. Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be with ...
- 连接Linux下 XAMPP集成环境中部署的禅道的数据库MariaDB
用mysql数据库工具连接linuxmysql环境,但是会遇到连接失败的问题,如下所示: 这就需要涉及到另外的问题了,需要我们打开mysql的连接授权,具体的操作步骤如下: 1)在xshell里进入m ...
- EditText取消自动调用键盘事件(方法之一)
直接上代码,这只是其中一种方法: 重点在于是在该EditText的父空间中设置 <LinearLayout android:layout_width="match_parent&quo ...