比赛 叫图论的DP题 评测结果 AAAAAAAAAA
题目名称 魅力手镯 最终得分 100
用户昵称 bear 运行时间 0.139 s
代码语言 C++ 内存使用 0.39 MiB
提交时间 2017-08-29 21:14:13
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <limits>
#include <algorithm>
#include <iterator>
#include <memory.h>
#include <time.h>

using namespace std;

#define CUR_NAMESPACE namespace charm {
CUR_NAMESPACE

const int N = 3405;
const int C = 12885;

class Solver
{
private:
	int n, m;
	int weights[N];
	int values[N];
	int dp[C];
public:
	void Solve()
	{
		scanf("%d%d", &n, &m);
		for (int i = 0; i < n; i++) {
			scanf("%d%d", &weights[i], &values[i]);
		}
		for (int i = 0; i < n; i++) {
			for (int c = m; c >= weights[i]; c--) {
				dp[c] = max(dp[c], dp[c - weights[i]] + values[i]);
			}
		}
		printf("%d\n", dp[m]);
	}
} solver;

void Launch()
{
	solver.Solve();
}

#define NAMESPACE_END }
NAMESPACE_END

int main()
{
    freopen("charm.in", "r", stdin);
	freopen("charm.out", "w+", stdout);
	charm::Launch();
	return 0;
}