【BZOJ1708】[Usaco2007 Oct]Money奶牛的硬币【完全背包】

【题目链接】

裸完全背包,这题为什么是gold...

/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

const int maxn = 10005, maxv = 30;

int n, m, v[maxn];
LL dp[maxn];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

int main() {
	n = iread(); m = iread();
	for(int i = 1; i <= n; i++) v[i] = iread();
	dp[0] = 1;
	for(int i = 1; i <= n; i++) for(int j = v[i]; j <= m; j++)
		dp[j] += dp[j - v[i]];
	printf("%lld\n", dp[m]);
	return 0;
}


你可能感兴趣的:(完全背包)