比赛 叫图论的DP题 评测结果 AAAAAAAAAA
题目名称 开心的金明 最终得分 100
用户昵称 bear 运行时间 0.012 s
代码语言 C++ 内存使用 0.54 MiB
提交时间 2017-08-29 20:49:19
显示代码纯文本
#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;

typedef unsigned long long ULL;
typedef long long LL;

#define CUR_NAMESPACE namespace happy {
CUR_NAMESPACE

const int N = 25;
const int C = 3e4 + 5;

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

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

#define NAMESPACE_END }
NAMESPACE_END

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