需要按照B/C的值从大到小排序。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int maxn = ;
const int MOD = ; int A[maxn], B[maxn], C[maxn];
int dp[];
int vis[maxn]; struct node
{
int A, B, C;
bool friend operator < (node a, node b)
{
return 1.0*a.B/a.C > 1.0*b.B/b.C;
}
}P[maxn]; int main()
{
int T;
scanf("%d", &T); while(T--)
{
int n, t;
scanf("%d %d", &n, &t);
for(int i=; i<=n; i++)
scanf("%d %d %d", &P[i].A, &P[i].B, &P[i].C); sort(P+, P+n+);
memset(dp, , sizeof(dp)); for(int i=; i<= n; i++)
vis[i] = INF; for(int i=; i<=n; i++)
{
for(int j=t; j>=P[i].C; j--)
dp[j] = max(dp[j], dp[j-P[i].C] + P[i].A - P[i].B*j);
} int ans = ;
for(int i=; i<= t; i++)
ans = max(ans, dp[i]); printf("%d\n", ans);
}
return ;
}
/*
1
2 10
110 5 9
30 2 1
*/