Catalog
洛谷P1060-开心的金明(背包问题)

#include<iostream>
#include<algorithm>
using namespace std;
int weight[30],cost[30],f[10000];
int money,number;
int main(){

cin >> money >> number;
for(int i = 1;i <= number;i++){
cin >>cost[i] >>weight[i];
weight[i] *= cost[i];
}

for(int i = 1;i <= number;i++)
for(int j = money;j >= cost[i];j--)
f[j] = max(f[j],f[j - cost[i]] + weight[i]);
cout << f[money] <<endl;
return 0;
}
Author: superzhaoyang
Link: http://yoursite.com/2019/09/22/洛谷P1060-开心的金明(背包问题)/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • 微信
  • 支付宝

Comment