A - Coin Change
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
这道题有个坑点,题目不能超过100个硬币。也就是101 不能用101个一块的
除开这个就是完全揹包了。 我们加一个维度,表示当前用的硬币 dp[j][k] 表示当前在j元钱用了k个硬币一共有多少情况。
状态转移方程 : dp【j】【k】 += dp【j - v【i】】【k - 1】
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <ctype.h>
#include <bitset>
#define LL long long
#define ULL unsigned long long
#define mod 100000000
#define INF 0x7ffffff
#define mem(a,b) memset(a,b,sizeof(a))
#define MODD(a,b) (((a%b)+b)%b)
using namespace std;
const int maxn = 1e4 + 5;
int n,m;
int v[5] = {1,5,10,25,50};
int dp[maxn][105],dp2[maxn][105];
int main()
{
while(~scanf("%d",&n)){
mem(dp,0);
dp[0][0] = 1;
for(int i = 0; i < 5; i++){
for(int j = 1; j <= 100; j++){
for(int k = v[i]; k <= n; k++){
dp[k][j] += dp[k - v[i]][j - 1];
}
}
}
int ans = 0;
for(int i = 0; i <= 100; i++){
ans += dp[n][i];
}
printf("%d\n",ans);
}
return 0;
}