HDU1069:Monkey and Banana(最长上升子序列的应用)
2015-03-31 16:32
399 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069
这题挺简单的,给定一个箱子的长宽高,要求啰箱子,但必须保证下面箱子的长和宽必须大于上面的箱子。
一个箱子,有六种情况,排序后,按照最长上升子序列来求解就行了。
代码如下:
这题挺简单的,给定一个箱子的长宽高,要求啰箱子,但必须保证下面箱子的长和宽必须大于上面的箱子。
一个箱子,有六种情况,排序后,按照最长上升子序列来求解就行了。
代码如下:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int n,tt,dp[210]; struct node { int x,y,z; } q[210]; int cmp(const void *aa,const void *bb) { struct node *a=(struct node *)aa; struct node *b=(struct node *)bb; if(a->x!=b->x) return b->x-a->x; else if(a->y!=b->y) return b->y-a->y; else return b->z-a->z; } int main() { int K=0; int xx,yy,zz; int maxx; while(scanf("%d",&n)!=EOF&&n!=0) { ++K; tt=1; maxx=-inf; for(int i=0; i<n; i++) { scanf("%d%d%d",&xx,&yy,&zz); q[tt].x=xx; q[tt].y=yy; q[tt++].z=zz; q[tt].x=xx; q[tt].y=zz; q[tt++].z=yy; q[tt].x=yy; q[tt].y=xx; q[tt++].z=zz; q[tt].x=yy; q[tt].y=zz; q[tt++].z=xx; q[tt].x=zz; q[tt].y=xx; q[tt++].z=yy; q[tt].x=zz; q[tt].y=yy; q[tt++].z=xx; } qsort(q+1,tt+1,sizeof(q[1]),cmp); memset(dp,0,sizeof(dp)); dp[1]=q[1].z; maxx=max(maxx,q[1].z); for(int i=2;i<tt;i++) { for(int j=1;j<i;j++) { if(q[i].x<q[j].x&&q[i].y<q[j].y) { dp[i]=max(dp[i],dp[j]); } } dp[i]=dp[i]+q[i].z; maxx=max(maxx,dp[i]); } printf("Case %d: maximum height = %d\n",K,maxx); } return 0; }
相关文章推荐
- HDU 1069 Monkey and Banana(dp最长上升子序列)
- (博客搬迁)hdu1069 Monkey and Banana(最长不下降子序列)
- HDU 1069 Monkey and Banana 最长上升子序列模板
- hdu 1069 Monkey and Banana 最长上升子序列。
- hdu 1069 Monkey and Banana (最长上升子序列)
- Monkey and Banana(LIS最长上升子序列)
- hdu 1069 Monkey and Banana(dp 最长上升子序列)
- (DP,最长上升子序列变形)Monkey and Banana--HDOJ
- HDU 1069 Monkey and Banana (dp, 最长上升子序列)
- HDU 1069 Monkey and Banana(LIS最长上升子序列)
- HDU - 1096 - Monkey and Banana(最长上升子序列)
- 动态规划1:H - Monkey and Banana(最长非上升子序列)
- HDU 1069 Monkey and Banana (最长上升子序列)
- (hdu step 3.2.6)Monkey and Banana(在第一关键字有序的情况下,根据第二关键字求最长上升子序列的高度之和)
- hdu 1069 Monkey and Banana(类似最长上升子序列,dp)
- HDU1069 Monkey and Banana(动态规划,单调最长递减子序列)
- HDU Monkey and Banana 1069 dp 动态规划 最长递增子序列
- hdu 1069 monkey and banana(最长下降子序列)
- HDU1069 Monkey and Banana(dp动态规划,最长非递减子序列变形题)
- hdu 1069 Monkey and Banana--最长递增子序列