[luoguP1474] 货币系统 Money Systems(背包)

传送门

背包

——代码

#include <cstdio>
#include <iostream>
#define LL long long

int v, n;
LL f[10001];

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

int main()
{
	int i, j, x;
	v = read();
	n = read();
	f[0] = 1;
	for(i = 1; i <= v; i++)
	{
		x = read();
		for(j = x; j <= n; j++) f[j] += f[j - x];
	}
	printf("%lld
", f[n]);
	return 0;
} 

  

原文地址:https://www.cnblogs.com/zhenghaotian/p/7054424.html