1005 ProblemE

来源:互联网 发布:如何采集新车交易数据 编辑:程序博客网 时间:2024/04/30 03:07

题意:
大意就是摆石块,给出石块的长宽高,求最高能摞多高,每种石块能用三次最多30块石块
思路:
每种石块按高度不同分为三种,也就是最多90块石块把他们放到数组里按照长宽由小到大排序。
然后判断第i块上放第j( j < i )块(包括j块之上的所有块)所有情况中哪种最高,把高度存下来
然后求出所有情况的最大值。
注意输出格式

#include<iostream>#include<algorithm>#include<string.h>#include<fstream>using namespace std;int ca = 0;int max(int a, int b){    return a > b ? a : b;}struct Block{    int x;    int y;    int z;}block[91];int dp[91];bool cmp(Block a,Block b){    if (a.x != b.x)return a.x<b.x;    else return a.y<b.y;}void X3(int n, int a, int b, int c){    if (a < b)     {        block[n].x = a;        block[n].y = b;    }    else    {        block[n].x = b;        block[n].y = a;    }    block[n].z = c;}int main(){    //fstream cin("E:/C++/IN/aaa.txt");    int n;    while (cin >> n&&n)    {        int height = 0;        memset(block, 0, 91);        int m = 0;        int a, b, c;        for (int i = 0;i < n;i++)        {            cin >> a >> b >> c;            X3(++m, a, b, c);            X3(++m, a, c, b);            X3(++m, c, b, a);        }        sort(block, block+m+1,cmp);        memset(dp, 0, 91);        for (int i = 0;i<=m;i++)        {            height = 0;            for (int j = 0;j <i;j++)            {                if (block[j].x < block[i].x&&block[j].y<block[i].y)                    height = max(height, dp[j]);            }            dp[i] = height + block[i].z;        }        for (int i = 0;i < 91;i++)        {            height = max(height,dp[i]);        }    cout << "Case " << ++ca << ": maximum height = " << height << endl;    }    return 0;}
0 0