poj3624

赤裸裸的01背包

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

const int maxn = 3410, maxm = 12890;

int main()
{
	//freopen("D:\\t.txt", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	int f[maxm];
	memset(f, 0, sizeof(f));
	for (int i = 0; i < n; i++)
	{
		int w, d;
		scanf("%d%d", &w, &d);
		for (int j = m; j >= w; j--)
			if (f[j - w] + d > f[j])
				f[j] = f[j - w] + d;
	}
	printf("%d\n", f[m]);
	return 0;
}

你可能感兴趣的:(poj)