POJ 3624 Charm Bracelet 【DP】【01背包】

//9210453	ylwh	3624	Accepted	216K	235MS	C	397B	2011-08-22 14:05:30
#include <stdio.h>
#define N 3403
#define M 12881
int a[M];
int max(int x, int y)
{
	return x > y ? x : y;
}
int main()
{
	int n, m, i, j, w, d;
	while(scanf("%d%d", &n, &m) != EOF)
	{
		for(i=0; i<=m; i++)
			a[i] = 0;
		for(i=1; i<=n; i++)
		{
			scanf("%d%d", &w, &d);
			for(j=m; j>=w; j--)
				a[j] = max(a[j-w]+d, a[j]);
		}
		printf("%d\n", a[m]);
	}
    return 0;
}

趴了一会儿,终于明白01背包到底是什么情况了,哈哈哈~~

你可能感兴趣的:(POJ 3624 Charm Bracelet 【DP】【01背包】)