#include <stdio.h> #include <string.h> #define min(a,b) a<b ? a:b const int maxn = 115; const int INF = 1000000000; int f[maxn][maxn];//f[i][j]表示第i個階段耗費j點力量時,的最小耗時。 int main() { int i, j, t, n, m, t1, t2, t3, f1, f2; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (i = 0; i <= n; i++) for (j = 0; j <= m; j++) f[i][j] = INF; f[0][m] = 0; for (i = 1; i <= n; i++) { scanf("%d%d%d%d%d", &t1, &t2, &t3, &f1, &f2); for (j = 0; j <= m; j++) { if (j >= f1) f[i][j - f1] = min(f[i][j - f1], f[i - 1][j] + t1); f[i][j] = min(f[i][j], f[i - 1][j] + t2); if (j + f2 <= m) f[i][j + f2] = min(f[i][j + f2], f[i - 1][j] + t3); else f[i][m] = min(f[i][m], f[i - 1][j] + t3); } } int minn = INF; for (i = 0; i <= m; i++) if (f[n][i] < minn) minn = f[n][i]; printf("%d\n", minn); } return 0; } #include <stdio.h> #include <string.h> #define min(a,b) a<b ? a:b const int maxn = 115; const int INF = 1000000000; int f[maxn][maxn];//f[i][j]表示第i個階段耗費j點力量時,的最小耗時。 int main() { int i, j, t, n, m, t1, t2, t3, f1, f2; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (i = 0; i <= n; i++) for (j = 0; j <= m; j++) f[i][j] = INF; f[0][m] = 0; for (i = 1; i <= n; i++) { scanf("%d%d%d%d%d", &t1, &t2, &t3, &f1, &f2); for (j = 0; j <= m; j++) { if (j >= f1) f[i][j - f1] = min(f[i][j - f1], f[i - 1][j] + t1); f[i][j] = min(f[i][j], f[i - 1][j] + t2); if (j + f2 <= m) f[i][j + f2] = min(f[i][j + f2], f[i - 1][j] + t3); else f[i][m] = min(f[i][m], f[i - 1][j] + t3); } } int minn = INF; for (i = 0; i <= m; i++) if (f[n][i] < minn) minn = f[n][i]; printf("%d\n", minn); } return 0; }