HDOJ-2069 Coin Change(母函数)
2016-03-19 20:44
513 查看
这道题比比普通母函数题多了个限制就是总硬币数不能超过100,那么在记录每种方案时,同时要记录构成该种方案的硬币数.
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <climits> #include <vector> using namespace std; #define maxn 255 int num[5] = {1, 5, 10, 25, 50}; vector<int> v1[maxn], v2[maxn]; int main(){ //freopen("in.txt", "r", stdin); int n; while(cin >> n){ for(int i = 0; i <= n; i++){ v1[i].clear(); v2[i].clear(); } v1[0].push_back(0); v2[0].push_back(0); for(int i = 0; i < 5; i++){ for(int j = 0; j < n; j++){ for(int h = 1; h <= 100 && h*num[i] + j <= n; h++){ for(int p = 0; p < v1[j].size(); p++){ if(v1[j][p] + h <= 100){ int m = h * num[i] + j; v2[m].push_back(v1[j][p]+h); } } } } for(int h = 0; h <= n; h++) v1[h] = v2[h]; } cout << v1 .size() << endl; } return 0; }
相关文章推荐
- LeetCode108—Convert Sorted Array to Binary Search Tree
- Struts2中jsp前台传值到action后台的三种方式 <转载>属性加载,模型加载
- ffmpeg参数中文详细解释
- java中的常用类、Date和SimpleDateFormat类表示时间、java中基本类型和包装之间的转换
- 第四周项目5递归求阶乘
- 记codeforces两题
- Hibernate逍遥游记-第2章-使用hibernate.properties
- debian ubuntu linux系好用的包管理工具 aptitude
- 输入一个多项式F(X) 计算出(F(X))^P
- 简单谈谈C++中的引用与指针
- 关于surf显示立体图,可视化分析数据
- 初识NuGet - 概念, 安装和使用
- jdk环境变量配置
- Ajax and php 2.5
- Android四大组件之Service工作原理
- 转自一位学长的日志安排
- 学习进度条(三)
- 压缩感知的MP算法
- VTK环境搭建注意事项
- 软件测试作业(三)