这个题也能够用递归加记忆化搜索来A,只是因为这题比較简单,所以用来做母函数的入门题比較合适

以展开后的x4为例,其系数为4,即4拆分成1、2、3之和的拆分数为4;

即 :4=1+1+1+1=1+1+2=1+3=2+2

这里再引出两个概念整数拆分和拆分数:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>
using namespace std;
int b[200],a[200];
int main()
{
int n;
int i,j,k;
while(cin>>n)
{
for(i=0;i<=n;i++)//这是对第一个表达式进行初始化
{
a[i]=1;
b[i]=0;
}
for(i=2;i<=n;i++)// i从2到n遍历,这里i就是指第i个表达式,上面给出的另外一种母函数关系式里,每个括号括起来的就是一个表达式。
{
for(j=0;j<=n;j++)//j 从0到n遍历,这里j就是仅仅一个表达式里第j个变量,比方在第二个表达式里:(1+x2+x4....)里。第j个就是x2*j.
{
for(k=0;k+j<=n;k+=i) //k表示的是第j个指数。所以k每次增i(由于第i个表达式的增量是i)。
b[j+k]+=a[j];
}
for(j=0;j<=n;j++)//把b的值赋给a,而把b初始化为0,由于b每次是从一个表达式中開始的
{
a[j]=b[j];
b[j]=0;
}
}
cout<<a[n]<<endl;
}
return 0;
}

HDU1028Ignatius and the Princess III母函数入门的更多相关文章

  1. HDU1028Ignatius and the Princess III(母函数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1028 母函数: 例1:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? 如何解决这 ...

  2. HDU-1028-Ignatius and the Princess III(母函数)

    链接: https://vjudge.net/problem/HDU-1028 题意: "Well, it seems the first problem is too easy. I wi ...

  3. hdu--1028--Ignatius and the Princess III (母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  4. Ignatius and the Princess III(母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  6. HDU 1028Ignatius and the Princess III(母函数简单题)

     Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. 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 ...

  8. hdu 1028 Ignatius and the Princess III(母函数入门+模板)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

  9. 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 ...

随机推荐

  1. Windows Azure中的Affinity Group

    Affinity Group: (近亲组?个人认为直译为近亲组更好一些,不知道官方是怎么翻译的). 如何创建Affinity Group 1. 进入https://manage.windowsazur ...

  2. 获取ocx运行路径的另一种方法

    在InitInstance里边可以获取   1 2 3 4 5 6 7 8 9 10 11 12     if (bInit)     {         // TODO: 在此添加您自己的模块初始化 ...

  3. 将Ojective-C代码移植转换为Swift代码

    相比于Objective-C,Swift语言更加简练.有时我们需要把原来写的一些Objective-C代码转换成Swift,下面总结了各种常见的情况. 1,构造函数的迁移 Objective-C为: ...

  4. Android installed app, never used, cannot receiver BroadcastReceiver

    官方文档是这么写的:(http://developer.android.com/about/versions/android-3.1.html#launchcontrols) Launch contr ...

  5. 一个好用的Dialog插件

    网页中常常须要弹出dialog,尽管非常多JS开源框架都提供这个功能,可是效果都不是非常好,比方easy-UI.改动样式这些又不是我擅长的,身边又没有美工兄弟,苦逼啊! (Easy-UI的BasicD ...

  6. java学习笔记06--正则表达式

    java学习笔记06--正则表达式 正则表达式可以方便的对数据进行匹配,可以执行更加复杂的字符串验证.拆分.替换等操作. 例如:现在要去判断一个字符串是否由数字组成,则可以有以下的两种做法 不使用正则 ...

  7. Xcode免证书真机调试,解决cannot read entitlement data问题

    本文是根据某个帖子写的(帖子链接在最后放出),但是在配置的过程中,遇到了一个纠结的问题,这个问题折腾了我N久,一直没搞明白到底是什么原因,问题如下: 按照原帖上写的每一步去做了,但是在最后编译的时候出 ...

  8. Storyboard 经常用法总结-精华版

    1.prepareForSegue: Now we know what the destinationViewController is we can set its data properties. ...

  9. iframe动态创建及释放内存

    近期參与一个项目的开发,因为项目是基于浏览器的胖client(RIA)应用程序,页面中大量调用iframe.后期測试发现浏览器内存一直居高不下,并且打开iframe页面越多内存占用越大.在IE系列浏览 ...

  10. GitLab 5.3 升级注意事项

    最主要就是需要更新的Git.我的Ubuntu12.04通过apt-get install安装的git版本过低. 所以只能通过源代码安装. 参考下面的步骤: wget git-core.googleco ...