| 比赛 | 叫图论的DP题 | 评测结果 | AAAAAAAAAA | 
    | 题目名称 | 开心的金明 | 最终得分 | 100 | 
    | 用户昵称 | 东林桂香 | 运行时间 | 0.007 s | 
    | 代码语言 | C++ | 内存使用 | 0.43 MiB | 
    | 提交时间 | 2017-08-29 19:35:01 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int a[30],b[30];
int c[30];
int f[30040];
int main()
{
	freopen("happy.in","r",stdin);
	freopen("happy.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		c[i]=a[i]*b[i];
	}
	for(int i=1;i<=m;i++)
	  for(int j=n;j>=a[i];j--)
	    f[j]=max(f[j],f[j-a[i]]+c[i]);
	printf("%d",f[n]);
	fclose(stdin);
	fclose(stdout);
	return 0;
}