两道母函数的模板题:

http://acm.hdu.edu.cn/showproblem.php?pid=1398

View Code

#include<iostream>#include<cstdio>using namespace std;int c1[310],c2[310];int main(){int n,i,j,k;while(scanf("%d",&n),n)    {for(i=0;i<=n;i++)        {            c1[i]=1;            c2[i]=0;        }for(i=2;i*i<=n;i++)        {for(j=0;j<=n;j++)for(k=0;k+j<=n;k+=i*i)        c2[k+j]+=c1[j];for(j=0;j<=n;j++)        {            c1[j]=c2[j];            c2[j]=0;        }        }        printf("%d\n",c1[n]);    }return 0;}

http://acm.hdu.edu.cn/showproblem.php?pid=1028

View Code

#include<iostream>#include<cstdio>using namespace std;int c1[130],c2[130];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=0;k+j<=n;k+=i)        c2[k+j]+=c1[j];for(j=0;j<=n;j++)        {            c1[j]=c2[j];            c2[j]=0;        }        }        printf("%d\n",c1[n]);    }return 0;}

转载于:https://www.cnblogs.com/LT-blogs/archive/2011/11/26/2264499.html

hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III相关推荐

  1. HDU 1398 Square Coins

    母函数简单应用 题目: Square Coins Problem Description People in Silverland use square coins. Not only they ha ...

  2. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

  3. HDU 1028 Ignatius and the Princess III

    //强行递推. xx[i][j]表示i数中第j个开头的组合种类. /* 最终结果[i]为 sum of(xx[i][j])  (j from 1  to i); xx[i][j]=sum of (xx ...

  4. hdu 1028 Ignatius and the Princess III 母函数入门

    传送门 文章目录 题意: 思路: 题意: 给你一个数nnn,问你有多少种方案用1−n1-n1−n的数能组成nnn,数的使用次数无限制. n≤120n\le120n≤120 思路: 考虑构造母函数. 对 ...

  5. HUOJ 1028 Ignatius and the Princess III(完全背包计数问题)

    为了字节跳动的面试,复习一波算法 题目描述:输入一个n,输出n的所有组成方案,例如: n=4,有 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + 1 + 1; 4 = 1 + ...

  6. LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告

    提交人:侯建鹏 提交日期:2012/4/16 1002 Ignatius and the Princess III 解题思路(一):动态规划 先设置int p[N][N]; Dp 方程为:p[i][j ...

  7. HDOJ 1398 Square Coins

    母函数"第一季",无压力AC~ View Code 1 //#include <fstream> 2 #include <iostream> 3 using ...

  8. HDU 1028 HDU Ignatius and the Princess III

    简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () {int i,j,dp[12 ...

  9. HDU-1028 Ignatius and the Princess III(生成函数)

    题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...

最新文章

  1. 在解决方案中所使用 NuGet 管理软件包依赖
  2. Java程序员涨薪必备技能
  3. sqlserver生成脚本
  4. cad常用字体包_水利设计CAD基础篇(一)
  5. Android系统为例解读智能手机如何防盗
  6. 文件上传表单 上传文件的细节 文件上传下载和数据库结合
  7. 创业者在创业时经常会问到的一个问题
  8. 数据分析、python速成班?包就业?扒一扒数据行业黑幕
  9. python代码翻译器-我用40行python代码写一个桌面翻译器,很nice
  10. 关于STM32 __IO 的变量定义
  11. java fx combox,combobox – 带有FXML的组合框JavaFx
  12. 不瞒你说,我最近跟Java源码杠上了
  13. elixir 简单的server,client
  14. 【量化笔记】通道突破策略
  15. Foxmail 设置自动落款签名
  16. 有的放矢-电气工程师的工作重心
  17. 无法连接虚拟设备sata0:1,因为主机上没有相应的设备
  18. 一个完整的嵌入式程序_放下偏见,原来嵌入式程序员如此“妖娆”!
  19. Delphi2010设置成Delphi7风格
  20. 使用XML的方式导出EXCEL

热门文章

  1. bzoj1562 [NOI2009]变换序列
  2. spring RestTemplate用法详解
  3. 构造函数失败_抛出异常
  4. android 隐藏系统键盘
  5. 用Delphi制作网络游戏外挂
  6. 不敢相信!美国预测10年后的世界!
  7. python orm_python的orm
  8. 资深架构师手把手教你性能优化
  9. 漫画: 可以给女朋友讲解 Linux 内核长啥样了
  10. 谷歌、阿里巴巴他们都来了,你呢?