国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

How to eat more Banana

2019-11-08 01:37:59
字體:
來源:轉載
供稿:網友

How to eat more Banana

時間限制:1000 ms  |  內存限制:65535 KB難度:4描述 A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, PRovide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked. Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.輸入The input file will contain one or more test cases. The first line of each test case contains an integer n,representing the number of different blocks in the following data set. The maximum value for n is 30.Each of the next n lines contains three integers representing the values xi, yi and zi.Input is terminated by a value of zero (0) for n.輸出For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".樣例輸入
110 20 3026 8 105 5 571 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 53 5897 93 2384 62 6433 83 270樣例輸出
Case 1: maximum height = 40Case 2: maximum height = 21Case 3: maximum height = 28Case 4: maximum height = 342

題意:

把給定的長方體(不限)疊加在一起,疊加的條件是,上面一個長方體的長和寬都比下面長方體的長

和寬短;求這些長方體能疊加的最高的高度.(其中(3,2,1)可以擺放成(3,1,2)、(2,1,3)等).

PS:每塊積木最多有3 個不同的底面和高度,我們可以把每塊積木看成三個不同的積木,那么n種類型的積木就轉化為3*n個不同的積木,對這3* n個積木的長按照從大到小排序;然后找到一個遞減的子序列,使得子序列的高度和最大。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;struct node{    int q,w,e;}a[10000];int dp[10000];bool cmp(node a,node b){    if(a.q!=b.q)    return a.q>b.q;    else    return a.w>b.w;}int main(){    int n;    int g=0;    while(scanf("%d",&n)!=-1)    {        memset(dp,0,sizeof(dp));        if(n==0)            break;        ++g;        int p=0;        int z,x,c;        int ha[4];        for(int i=0;i<n;i++)        {            scanf("%d%d%d",&ha[0],&ha[1],&ha[2]);            sort(ha,ha+3);           a[p].q=ha[0];           a[p].w=ha[1];           a[p].e=ha[2];           p++;           a[p].q=ha[0];           a[p].w=ha[2];           a[p].e=ha[1];           p++;           a[p].q=ha[1];           a[p].w=ha[2];           a[p].e=ha[0];           p++;        }        sort(a,a+p,cmp);        int sum=0;        int maxn=0;        for(int i=0;i<p;i++)        {dp[i]=a[i].e;            for(int j=i;j>=0;j--)            {                if(a[j].q>a[i].q&&a[j].w>a[i].w)                {                    dp[i]=max(dp[i],dp[j]+a[i].e);                }            }            if(dp[i]>maxn)            {                maxn=dp[i];            }        }        printf("Case %d: maximum height = ",g);        printf("%d/n",maxn);    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连城县| 罗城| 九江市| 富川| 田阳县| 阿城市| 聂荣县| 西乌珠穆沁旗| 巨鹿县| 贵溪市| 石楼县| 右玉县| 和平区| 察隅县| 巨野县| 和硕县| 广昌县| 夏河县| 乐亭县| 宁南县| 安达市| 湖口县| 福鼎市| 常山县| 渑池县| 荣昌县| 丹棱县| 双桥区| 津市市| 剑阁县| 汉川市| 多伦县| 广昌县| 嘉义县| 石门县| 宁远县| 夏河县| 秭归县| 长葛市| 酉阳| 湘潭县|