【HDOJ】3127 WHUgirls

时间:2023-03-08 17:39:11
 #include <stdio.h>
#include <string.h> #define mymax(a, b) (a>b) ? a:b typedef struct {
int x, y, c;
} rect_st; rect_st rects[]; int dp[][]; int main() {
int case_n;
int x, y, n;
int i, j, k, tmp; scanf("%d", &case_n); while (case_n--) {
scanf("%d%d%d", &n,&x,&y);
for (i=; i<=n; ++i)
scanf("%d%d%d", &rects[i].x, &rects[i].y, &rects[i].c);
memset(dp, , sizeof(dp));
for (i=; i<=x; ++i) {
for (j=; j<=y; ++j) {
for (k=; k<=n; ++k) {
if (i>=rects[k].x && j>=rects[k].y) {
tmp = mymax(dp[i-rects[k].x][j]+dp[rects[k].x][j-rects[k].y], dp[i][j-rects[k].y]+dp[i-rects[k].x][rects[k].y]);
dp[i][j] = mymax(dp[i][j], tmp+rects[k].c);
}
if (i>=rects[k].y && j>=rects[k].x) {
tmp = mymax(dp[i-rects[k].y][j]+dp[rects[k].y][j-rects[k].x], dp[i][j-rects[k].x]+dp[i-rects[k].y][rects[k].x]);
dp[i][j] = mymax(dp[i][j], tmp+rects[k].c);
}
}
}
}
printf("%d\n", dp[x][y]);
} return ;
}

完全背包。