您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: