uva674 - Coin Change(完全背包)

题目:uva674 - Coin Change(完全背包)

题目大意:给1 5 10 25 50 这5中面值的硬币,然后给出N,问用这些钱组成N的不同方式数目。1 5 和 5 1 表示同一中,顺序不同算相同。

解题思路:完全背包。 状态方程:dp【j】 += dp【 j - v【i】】;

代码:

#include <cstdio>
#include <cstring>

const int N = 5;
const int maxn = 8000;

typedef long long ll;

int n;
int v[N] = {1, 5, 10, 25, 50};
//ll dp[maxn][N];
ll d[maxn];

/*void init () {

	memset (dp, -1, sizeof (dp));//have not been search
	for (int i = 0; i < N; i++)
		dp[0][i] = 1;
}*/

/*ll DP (int x, int k) {

	ll& ans = dp[x][k];
	if (ans != -1)
		return ans;
	ans = 0;
	for (int i = k; i < N && x >= v[i]; i++)
			ans += DP(x - v[i], i);
	return ans;
}*/

int main () {

//	init();
	memset (d, 0, sizeof (d));
	d[0] = 1;

	for (int i = 0; i < N; i++)
		for (int j = v[i]; j <= maxn; j++)
			d[j] += d[j - v[i]]; 

	while (scanf ("%d", &n) != EOF) {

		//printf ("%lld\n", DP(n, 0));
		printf ("%lld\n", d[n]);
	}
	return 0;
}

uva674 - Coin Change(完全背包),布布扣,bubuko.com

时间: 2024-08-09 02:05:57

uva674 - Coin Change(完全背包)的相关文章

LightOJ 1231 Coin Change (I) (背包计数模板题)

1231 - Coin Change (I) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB In a strange shop there are n types of coins of valueA1, A2 ... An.C1, C2,... Cn denote the number of coins of valueA1, A2... An respectively. You have

Light oj 1233 - Coin Change (III) (背包优化)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1233 题目就不说明了. 背包的二进制优化,比如10可以表示为1 2 4 3,而这些数能表示1 ~ 10的任意的数.然后类似01背包就好了. 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdlib> 5 #include &l

dp背包问题/01背包,完全背包,多重背包,/coin change算法求花硬币的种类数

一步一步循序渐进. Coin Change 具体思想:给你 N元,然后你有几种零钱S={S1,S2...,Sm} (每种零钱数量不限). 问:凑成N有多少种组合方式  即N=x1 * S1+x2*S2+...+xk*Sk (xk>=0,k=1,2..m) 设有f(x)中组合方式 有两种解答(自底向上回溯): 1.不用第m种货币   f(N,m-1) 2.用第m种货币 f(N-Sm,m) 总的组合方式为f(N,m)=f(N,m-1)+f(N-Sm,m) anything is nonsense,s

hdu 2069 Coin Change(完全背包)

Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16592 Accepted Submission(s): 5656 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent.

Lightoj 1231 - Coin Change (I) (裸裸的多重背包)

题目链接: Lightoj  1231 - Coin Change (I) 题目描述: 就是有n种硬币,每种硬币有两个属性(价值,数目).问用给定的硬币组成K面值,有多少种方案? 解题思路: 赤果果的多重背包,简单搞一下就好了.席八!烦烦烦.今天绝对是出门刷提前没看黄历,刚开始套了一个多重背包板子,蓝而跑出来的答案并不对,改来改去就错在细节的地方. 1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4

hdu 2069 Coin Change 背包。本来打算用母函数再写一遍的,发现代码极其相似,就没写

Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14982    Accepted Submission(s): 5070 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and

[LeetCode][JavaScript]Coin Change

Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination o

Leetcode OJ --- 322. Coin Change

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins,

HDU 2069 Coin Change

Coin Change Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 206964-bit integer IO format: %I64d      Java class name: Main Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We