HDU 2069 母函数模版题
2017-08-09 20:03
405 查看
传送门
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20297 Accepted Submission(s): 7136
Problem Description
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents
with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input
11
26
Sample Output
4
13
Author
Lily
Source
浙江工业大学网络选拔赛
Recommend
linle
板子留给自己用的。
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20297 Accepted Submission(s): 7136
Problem Description
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents
with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input
11
26
Sample Output
4
13
Author
Lily
Source
浙江工业大学网络选拔赛
Recommend
linle
板子留给自己用的。
//china no.1 #pragma comment(linker, "/STACK:1024000000,1024000000") #include <vector> #include <iostream> #include <string> #include <map> #include <stack> #include <cstring> #include <queue> #include <list> #include <stdio.h> #include <set> #include <algorithm> #include <cstdlib> #include <cmath> #include <iomanip> #include <cctype> #include <sstream> #include <functional> #include <stdlib.h> #include <time.h> #include <bitset> using namespace std; #define pi acos(-1) #define endl '\n' #define srand() srand(time(0)); #define me(x,y) memset(x,y,sizeof(x)); #define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++) #define close() ios::sync_with_stdio(0); cin.tie(0); #define FOR(x,n,i) for(int i=x;i<=n;i++) #define FOr(x,n,i) for(int i=x;i<n;i++) #define W while #define sgn(x) ((x) < 0 ? -1 : (x) > 0) #define bug printf("***********\n"); typedef long long LL; const int INF=0x3f3f3f3f; const LL LINF=0x3f3f3f3f3f3f3f3fLL; const int dx[]={-1,0,1,0,1,-1,-1,1}; const int dy[]={0,1,0,-1,-1,1,-1,1}; const int maxn=1e3+10; const int maxx=3e5+100; const double EPS=1e-7; const int mod=10000007; #define mod(x) ((x)%MOD); template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);} template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);} template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));} template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));} inline LL Scan() { int f=1;char C=getchar();LL x=0; while (C<'0'||C>'9'){if (C=='-')f=-f;C=getchar();} while (C>='0'&&C<='9'){x=x*10+C-'0';C=getchar();} x*=f;return x; } //freopen( "in.txt" , "r" , stdin ); //freopen( "data.out" , "w" , stdout ); //cerr << "run time is " << clock() << endl; int n,a[maxn][105],b[maxn][105],i,j,k,l,v[18]={0,1,5,10,25,50}; int main() { //freopen( "in.txt" , "r" , stdin ); while (scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0;i<=100;i++) a[i][i]=1; for(i=2;i<=5;i++) { //maxx+=num[i]*money[i]; for(j=0;j<=n;j++) for(k=0;k+j<=n;k+=v[i])//for(int k=0;k<=num[i]&&j+k*v[i]<=maxx;k++) for(l=0;l+k/v[i]<=100;l++) b[k+j][l+k/v[i]]+=a[j][l]; for(k=0;k<=n;k++) for(l=0;l<=100;l++) { a[k][l]=b[k][l]; 4000 b[k][l]=0; } } int sum=0; for(int i=0;i<=100;i++) sum+=a [i]; cout<<sum<<endl; } return 0; } /* for(int i=1;i<=3;i++) { maxx+=num[i]*money[i]; for(int j=0;j<=maxx;j++) for(int k=0;k<=num[i] && j+k*money[i]<=maxx;k++) c2[j+k*money[i]]+=c1[j]; for(int j=0;j<=maxx;j++) { c1[j]=c2[j]; c2[j]=0; } } */
相关文章推荐
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- HDU 2069 母函数模版题
- [母函数]HDU 2069 Coin Change
- hdu--2082(母函数模版)
- HDU 2069 母函数
- (简单母函数进阶版,暴力)hdu 2069 Coin Change
- hdu 1028 母函数 模版题
- hdu 2069 Coin Change (母函数)
- HDU 2069 母函数
- hdu 2069 Coin Change (母函数)