标签:
对比一年前的代码 感觉STL用的略浪
1 #include <iostream> 2 #include <algorithm> 3 #include <queue> 4 #include <cstring> 5 #include <cstdio> 6 #include <vector> 7 #include <string> 8 #include <iterator> 9 #include <cmath> 10 #include <deque> 11 #include <stack> 12 #include <cctype> 13 using namespace std; 14 15 const int N = 6000; 16 const int INF = 0xfffffff; 17 18 typedef long long ll; 19 typedef long double ld; 20 21 #define INFL 0x7fffffffffffffffLL 22 #define met(a, b) memset(a, b, sizeof(a)) 23 #define rep(c, a, b) for (int c = a; c < b; c++) 24 #define nre(c, a, b) for (int c = a; c > b; c--) 25 26 struct box 27 { 28 int x, y, h; 29 bool operator < (const box &a) const 30 { 31 if (x != a.x) return x > a.x; 32 else return y > a.y; 33 } 34 }; 35 36 vector <box> a; 37 vector <int> dp; 38 39 int main () 40 { 41 int n, k = 1; 42 while (cin >> n, n) 43 { 44 int x[4]; 45 a.clear(); dp.clear(); 46 while (n--) 47 { 48 cin >> x[0] >> x[1] >> x[2]; 49 sort (x, x + 3); 50 a.push_back ( (box){x[0], x[1], x[2]}); 51 a.push_back ( (box){x[0], x[2], x[1]}); 52 a.push_back ( (box){x[1], x[2], x[0]}); 53 } 54 sort (a.begin(), a.end()); 55 rep (i, 0, a.size()){ 56 dp.push_back(a[i].h); 57 rep (j, 0, i){ 58 if (a[j].x > a[i].x && a[j].y > a[i].y) 59 dp[i] = max (dp[i], dp[j] + a[i].h); 60 } 61 } 62 cout << "Case " << k++ << ": maximum height = "; 63 cout << * max_element (dp.begin(), dp.end()) << endl; 64 } 65 return 0; 66 }
标签:
原文地址:http://www.cnblogs.com/darkdomain/p/4403403.html