您的位置:首页 > 其它

hdoj--1069 Monkey and Banana(dp)

2016-03-29 18:28 441 查看
hdoj 1069

题解

按面积排序,LIS.

#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;

struct block{
int x, y, z;
block(int x, int y, int z):x(x), y(y), z(z){}
};
vector<block> vec;

int cmp(const block& a, const block& b)
{
return a.x * a.y < b.x * b.y;
}

inline void append(int x, int y, int z)
{
vec.push_back(block(x, y, z));
vec.push_back(block(x, z, y));
vec.push_back(block(y, x, z));
vec.push_back(block(y, z, x));
vec.push_back(block(z, x, y));
vec.push_back(block(z, y, x));
}

int main()
{
#ifdef LOCAL
fstream cin("data.in");
#endif // LOCAL
ios::sync_with_stdio(0);
cin.tie(0);

int kcase = 0;
int n;

while(cin >> n && n)
{
vec.clear();
int x, y, z;
for(int i = 0; i < n; ++i)
{
cin >> x >> y >> z;
append(x, y, z);
}

sort(vec.begin(), vec.end(), cmp);
int dp[vec.size()];
int ans = 0;
for(int i = 0; i < (int)vec.size(); ++i)
{
dp[i] = vec[i].z;
for(int j = 0; j < i; ++j)
if(vec[i].x > vec[j].x && vec[i].y > vec[j].y)
dp[i] = max(dp[i], dp[j] + vec[i].z);
ans = max(ans, dp[i]);
}
cout << "Case " << ++kcase <<": maximum height = " << ans << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdoj dp easy