标签:blog http io ar os sp for strong 数据
蚂蚁终于把尽可能多的食材都搬回家了,现在开始了大厨计划。
已知一共有 n 件食材,每件食材有一个美味度 Ai 和新鲜度 Bi , 如果蚂蚁在第t时刻将第i样食材烹饪成功,则得到Ai-t*Bi 的美味指数,当然,用第i件食材做饭要花去 Ci 的时间。
众所周知,蚂蚁的厨艺不怎么样,所以他需要你设计做饭方案使得在时间 T 内完成的美味指数最大。6 1 200 5 1
195
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
struct node {
int a,b,c;
} p[52];
int dp[100010];
bool cmp(const node &x,const node &y) {
return y.c*x.b > x.c*y.b;
}
int main() {
int t,n,i,j,ans;
while(~scanf("%d %d",&t,&n)) {
for(i = 0; i < n; i++)
scanf("%d %d %d",&p[i].a,&p[i].b,&p[i].c);
sort(p,p+n,cmp);
memset(dp,0,sizeof(dp));
for(ans = i = 0; i < n; i++) {
for(j = min(t,p[i].a/p[i].b); j >= p[i].c; j--) {
dp[j] = max(dp[j],dp[j-p[i].c]+p[i].a-j*p[i].b);
if(dp[j] > ans) ans = dp[j];
}
}
printf("%d\n",ans);
}
return 0;
}
标签:blog http io ar os sp for strong 数据
原文地址:http://www.cnblogs.com/a972290869/p/4099940.html