需要按照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+7; const int maxn = 1015; const int MOD = 9973; int A[maxn], B[maxn], C[maxn]; int dp[3005]; 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=1; i<=n; i++) scanf("%d %d %d", &P[i].A, &P[i].B, &P[i].C); sort(P+1, P+n+1); memset(dp, 0, sizeof(dp)); for(int i=1; i<= n; i++) vis[i] = INF; for(int i=1; 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 = 0; for(int i=0; i<= t; i++) ans = max(ans, dp[i]); printf("%d\n", ans); } return 0; } /* 1 2 10 110 5 9 30 2 1 */
时间: 2024-11-03 23:53:06