这个题也能够用递归加记忆化搜索来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. JSP中两种include的区别

    首先说明这两种都是什么: <%@ include file=”relativeURI”%> 可以叫作静态include(静态包含),是jsp指令中的一种,(JSP指令控制JSP编译器如何去 ...

  2. CF 17B Hierarchy

    Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinat ...

  3. 文顶顶 iOS开发UI篇—UITabBarController简单介绍 iOS开发UI篇—UITabBarController简单介绍

    一.简单介绍 UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例 ...

  4. c#调用语音功能

    转自 http://www.cnblogs.com/Hans2Rose/p/WeatherSpeaker.html .Net里面自带了一个语音类库:System.Speech,调用系统的语音功能,就能 ...

  5. POJ 1166 The Clocks

    高斯消元法第四个冠军,这个称号是非常令人兴奋~~ 题目大意: 给出9个钟表的状态.给出九种操作,问最少要操作几次能把全部的钟表调回12点. 解题思路: 对于9个钟表分别列方程,然后高斯消元就可以.因为 ...

  6. 使用Android简单实现有道电子词典

    前言: 毕业设计的内容,仅仅有Java基础.没学过Android. 本着用到什么学什么.花费了10多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...

  7. thinkphp 3.2.3 入门示例

    原文:thinkphp3.2 1.安装WAMPServer,到D:\wamp\. 2.下载ThinkPHP3.2.3核心版.解压缩后,放到D:\wamp\www\MyWeb\.打开浏览器,输入网址:h ...

  8. java中Executor、ExecutorService、ThreadPoolExecutor介绍(转)

    1.Excutor 源码非常简单,只有一个execute(Runnable command)回调接口 public interface Executor { /**     * Executes th ...

  9. 黑马程序员:Java基础总结----泛型(高级)

    黑马程序员:Java基础总结 泛型(高级)   ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 泛型(高级) 泛型是提供给javac编译器使用的,可以限定集合中的输入类型 ...

  10. ThinkPHP的连贯操作方法中field方法

    ThinkPHP的连贯操作方法中field方法有很多的使用技巧,field方法主要目的是标识要返回或者操作的字段,下面详细道来. 1.用于查询 在查询操作中field方法是使用最频繁的. $Model ...