http://acm.hdu.edu.cn/showproblem.php?pid=5501
考虑t1,t2
t1先做的话,那么消耗c1*b1+b2*(C1+c2)
t2先做的话,那么消耗c2*b2+b1*(c1+c2)
可以看出c1b2和b1c2不同,其他的都相同,所以排序标准确定了。
Problem Description The SDOI in 2045 is far from what it was been 30 years ago. Each competition has t minutes and n problems.
Input There is an positive integer T(T≤10) in the first line for the number of testcases.(the number of testcases with n>200 is no more than 5 )
Output For each testcase output a line for an integer, for the highest mark dxy will get in this competition.
Sample Input 1 4 10 110 5 9 30 2 1 80 4 8 50 3 2
Sample Output 88
Source |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[350000];
struct node{
ll A;
ll B;
ll C;
}arr[100000];
bool cmp(node t1,node t2)
{
return t2.B*t1.C<t1.B*t2.C;
}
int main()
{
ll T;
scanf("%lld",&T);
while(T--)
{
ll n,t;
memset(dp,0,sizeof(dp));
scanf("%lld%lld",&n,&t);
for(ll i=1; i<=n; i++)
{
scanf("%lld%lld%lld",&arr[i].A,&arr[i].B,&arr[i].C );
}
sort(arr+1,arr+n+1,cmp);
for(ll i=1; i<=n; i++)
{
for(ll j=t; j>=arr[i].C; j--)
{
dp[j]=max(dp[j],dp[j-arr[i].C]+arr[i].A-arr[i].B*j);
//dp[j]表示j时刻
}
}
ll ans = 0;
for(ll i = 0; i <=t; i++)
{
ans = max(ans, dp[i]);
}
printf("%lld\n", ans);
}
}