戳这里:
//题意:有三种积木,第0种 只能放在长和宽都严格小于它的积木上,第1种 只能放在长和宽都小于等于它 且 面积小于它的积木上,第2种 只能放在长和宽都小于等于它的积木上,dp 求积木的最高高度。
1 #include "bits/stdc++.h" 2 using namespace std; 3 int n; 4 struct Block 5 { 6 int a, b, c, d; 7 }block[1010]; 8 bool cmp(Block A, Block B) 9 {10 if(A.a != B.a) {11 return A.a < B.a;12 }13 if(A.b != B.b) {14 return A.b < B.b;15 }16 return A.d > B.d;17 }18 19 long long dp[1010];20 21 int main()22 {23 while(scanf("%d", &n) && n) {24 memset(dp, 0, sizeof(dp));25 int i;26 for(i = 1; i <= n; ++i) {27 scanf("%d%d%d%d", &block[i].a, &block[i].b, &block[i].c, &block[i].d);28 if(block[i].a > block[i].b) {29 swap(block[i].a, block[i].b);30 }31 }32 sort(block + 1, block + 1 + n, cmp);33 int j;34 for(i = 1; i <= n; ++i) {35 for(j = 0; j < i; ++j) {36 if(block[i].d == 0) {37 if(block[j].a <= block[i].a && block[j].b <= block[i].b) {38 dp[i] = max(dp[i], dp[j] + block[i].c);39 }40 }41 if(block[i].d == 1) {42 if((block[j].a <= block[i].a && block[j].b < block[i].b) || (block[j].a < block[i].a && block[j].b <= block[i].b)) {43 dp[i] = max(dp[i], dp[j] + block[i].c);44 }45 }46 if(block[i].d == 2) {47 if(block[j].a < block[i].a && block[j].b < block[i].b) {48 dp[i] = max(dp[i], dp[j] + block[i].c);49 }50 }51 }52 }53 long long res = 0;54 for(i = 1; i <= n; ++i) {55 res = max(res, dp[i]);56 }57 printf("%I64d\n", res);58 }59 }