hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III
两道母函数的模板题:
http://acm.hdu.edu.cn/showproblem.php?pid=1398
#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
#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相关推荐
- HDU 1398 Square Coins
母函数简单应用 题目: Square Coins Problem Description People in Silverland use square coins. Not only they ha ...
- HDU 1398 Square Coins
题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...
- 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 ...
- hdu 1028 Ignatius and the Princess III 母函数入门
传送门 文章目录 题意: 思路: 题意: 给你一个数nnn,问你有多少种方案用1−n1-n1−n的数能组成nnn,数的使用次数无限制. n≤120n\le120n≤120 思路: 考虑构造母函数. 对 ...
- 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 + ...
- LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告
提交人:侯建鹏 提交日期:2012/4/16 1002 Ignatius and the Princess III 解题思路(一):动态规划 先设置int p[N][N]; Dp 方程为:p[i][j ...
- HDOJ 1398 Square Coins
母函数"第一季",无压力AC~ View Code 1 //#include <fstream> 2 #include <iostream> 3 using ...
- HDU 1028 HDU Ignatius and the Princess III
简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () {int i,j,dp[12 ...
- HDU-1028 Ignatius and the Princess III(生成函数)
题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...
最新文章
- 在解决方案中所使用 NuGet 管理软件包依赖
- Java程序员涨薪必备技能
- sqlserver生成脚本
- cad常用字体包_水利设计CAD基础篇(一)
- Android系统为例解读智能手机如何防盗
- 文件上传表单 上传文件的细节 文件上传下载和数据库结合
- 创业者在创业时经常会问到的一个问题
- 数据分析、python速成班?包就业?扒一扒数据行业黑幕
- python代码翻译器-我用40行python代码写一个桌面翻译器,很nice
- 关于STM32 __IO 的变量定义
- java fx combox,combobox – 带有FXML的组合框JavaFx
- 不瞒你说,我最近跟Java源码杠上了
- elixir 简单的server,client
- 【量化笔记】通道突破策略
- Foxmail 设置自动落款签名
- 有的放矢-电气工程师的工作重心
- 无法连接虚拟设备sata0:1,因为主机上没有相应的设备
- 一个完整的嵌入式程序_放下偏见,原来嵌入式程序员如此“妖娆”!
- Delphi2010设置成Delphi7风格
- 使用XML的方式导出EXCEL