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
- 1005 ProblemE
- 1005 ProblemE
- probleme directshow wmv (手动创建graph)
- codeforces #397 problemE 解题报告 补题
- Mit der Dofus. ZIP loader.swf, Probleme? Lesen Sie weiter ..
- 2016sdau课程练习专题一 1004 problemE
- Codeforces Round #341 (Div. 2) problemE Wet Shark and Blocks 矩阵乘法 dp
- The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemE:Easy Task
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- Jenkins+maven+tomact
- 啊哈!算法--第01节--桶排序
- Maven多模块实战
- Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案
- Problem G: Array C
- 1005 ProblemE
- linux入门学习
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- EventBus3.0源码分析
- 程序员的基本学习素质
- 定位迭代器的中间位置
- RFC 3261 SIP(1-6)
- 66.[Leetcode]Plus One
- Python 类和实例