标签:bottom ace scanf eterm equal log opened search not
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16589 Accepted Submission(s): 8834
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int MAXN = 100; 4 5 int block[MAXN][3]; 6 int dp[MAXN][MAXN]; 7 8 int main() 9 { 10 int n, kase = 0; 11 while(scanf("%d",&n) && n) 12 { 13 int N = 0; 14 for(int i = 1; i<=n; i++) 15 { 16 int a, b, h; 17 scanf("%d%d%d", &a, &b, &h); 18 block[++N][0] = min(b,h), block[N][1] = max(b,h), block[N][2] = a; 19 block[++N][0] = min(a,h), block[N][1] = max(a,h), block[N][2] = b; 20 block[++N][0] = min(a,b), block[N][1] = max(a,b), block[N][2] = h; 21 } 22 23 int ans = -2000000; 24 memset(dp, 0, sizeof(dp)); 25 for(int i = 1; i<=N; i++) //初始化第一个 26 dp[1][i] = block[i][2], ans = max(dp[1][i], ans); 27 28 for(int i = 2; i<=N; i++) //第i个 29 for(int j = 1; j<=N; j++) //第i个放编号为j的块 30 for(int k = 1; k<=N; k++) //j能否放在k上 31 if(block[j][0]<block[k][0] && block[j][1]<block[k][1]) 32 dp[i][j] = max(dp[i][j], dp[i-1][k]+block[j][2]), ans = max(dp[i][j], ans); 33 34 printf("Case %d: maximum height = %d\n", ++kase, ans); 35 } 36 return 0; 37 }
LIS:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int MAXN = 100; 4 5 struct node 6 { 7 int a, b, h; 8 bool operator<(const node x){ 9 return a>x.a; 10 } 11 }block[MAXN]; 12 int dp[MAXN]; 13 14 int main() 15 { 16 int n, kase = 0; 17 while(scanf("%d",&n) && n) 18 { 19 int N = 0; 20 for(int i = 1; i<=n; i++) 21 { 22 int a, b, h; 23 scanf("%d%d%d", &a, &b, &h); 24 block[++N].a = min(b,h), block[N].b = max(b,h), block[N].h = a; 25 block[++N].a = min(a,h), block[N].b = max(a,h), block[N].h = b; 26 block[++N].a = min(a,b), block[N].b = max(a,b), block[N].h = h; 27 } 28 sort(block+1, block+1+N); 29 int ans = -2000000; 30 for(int i = 1; i<=N; i++) //初始化第一个 31 dp[i] = block[i].h, ans = max(ans, dp[i]); 32 33 for(int i = 1; i<=N; i++) 34 for(int j = 1; j<i; j++) 35 if(block[i].a<block[j].a && block[i].b<block[j].b) 36 dp[i] = max(dp[i], dp[j]+block[i].h), ans = max(ans, dp[i]); 37 38 printf("Case %d: maximum height = %d\n", ++kase, ans); 39 } 40 return 0; 41 }
HDU1069 Monkey and Banana —— 普通DP or LIS
标签:bottom ace scanf eterm equal log opened search not
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7620396.html