| 比赛 | 叫图论的DP题 | 评测结果 | AAAAAAAAAA | 
    | 题目名称 | 开心的金明 | 最终得分 | 100 | 
    | 用户昵称 | jmsyzsfq | 运行时间 | 0.016 s | 
    | 代码语言 | C++ | 内存使用 | 15.57 MiB | 
    | 提交时间 | 2017-08-29 20:40:18 | 
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
struct shopping {
int price,important,value;
}a[1000000];
int f[1000000];
int main(){
	freopen("happy.in","r",stdin);
	freopen("happy.out","w",stdout);
    int high,n;
    cin>>high>>n;
    for(int i=1; i<=n; i++) {
        cin>>a[i].price>>a[i].important;
        a[i].value=a[i].important*a[i].price;
    }
    for(int i=1; i<=n; i++)         
        for(int j=high; j>=a[i].price; j--)
            f[j]=max(f[j],f[j-a[i].price]+a[i].value);
	cout<<f[high];
    return 0;
}