Monkey and Banana

来源:互联网 发布:网络优化挣钱吗 编辑:程序博客网 时间:2024/06/09 13:47

求最长递减子序列, 但是要注意的是,长方体六个面都可以

#include <iostream>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <algorithm>using namespace std;#define MAXN 1000struct node{    int x, y, z;}sta[MAXN];int dp[MAXN];bool cmp(node a,node b){    if(a.x==b.x)    return a.y>b.y;    return a.x>b.x;}int main(){    int ca = 1, n;    int num = 0;    int d[3];    while(scanf("%d",&n) != EOF && n)    {        num = 0;        for( int i = 1; i <= n; i++)        {            scanf("%d %d %d",&d[0],&d[1],&d[2]);            sta[num].x=d[2];sta[num].y=d[1];sta[num].z=d[0];num++;            sta[num].x=d[2];sta[num].y=d[0];sta[num].z=d[1];num++;            sta[num].x=d[1];sta[num].y=d[0];sta[num].z=d[2];num++;                        sta[num].x=d[1];sta[num].y=d[2];sta[num].z=d[0];num++;            sta[num].x=d[0];sta[num].y=d[2];sta[num].z=d[1];num++;            sta[num].x=d[0];sta[num].y=d[1];sta[num].z=d[2];num++;        }        sort(sta, sta + num, cmp);        for( int i = 0; i < num; i++)             dp[i] = sta[i].z;        for( int i =  num - 2; i >= 0; i--)          for( int j = i+1; j < num; j++)                if((sta[i].x > sta[j].x && sta[i].y > sta[j].y))                    dp[i] = max(dp[i], dp[j] + sta[i].z);        int ans = 0;        for( int i = 0; i < num; i++)             ans = max(ans, dp[i]);       printf("Case %d: maximum height = ",ca++);       printf("%d\n",ans);    }    return 0;}


0 0
原创粉丝点击