fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <queue>
  4. #include <vector>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <algorithm>
  8. typedef long long int ll;
  9. using namespace std;
  10.  
  11. bool compare ( const pair<pair<ll,ll>,ll> &i, const pair<pair<ll,ll>,ll> &j) {
  12. return !(i.first.first < j.first.first && i.first.second < j.first.second);
  13. }
  14.  
  15.  
  16. ll n, i, j, LIS[24000], maxx, a, b, c;
  17. vector< pair <pair<ll, ll>, ll> > block;
  18. int main() {
  19.  
  20. while(1) {
  21. cin>>n;
  22. if(n == 0) break;
  23. for(i=0;i<n;++i) {
  24. cin>>a>>b>>c;
  25. block.push_back(make_pair(make_pair(a,b), c));
  26. block.push_back(make_pair(make_pair(a,c), b));
  27. block.push_back(make_pair(make_pair(b,a), c));
  28. block.push_back(make_pair(make_pair(b,c), a));
  29. block.push_back(make_pair(make_pair(c,a), b));
  30. block.push_back(make_pair(make_pair(c,b), a));
  31. }
  32. memset(LIS, 0, (20000)*sizeof(ll));
  33. sort(block.begin(), block.end(), compare);
  34.  
  35. LIS[0] = block[0].second;
  36. for(i=1;i<(6*n);++i) {
  37. maxx = -999;
  38. for(j=0;j<i;++j) {
  39. if(block[j].first.first > block[i].first.first && block[j].first.second > block[i].first.second) {
  40. maxx = (maxx < LIS[j] + block[i].second) ? (LIS[j] + block[i].second) : maxx;
  41. }
  42. }
  43. maxx = (maxx < block[i].second) ? (block[i].second) : maxx;
  44. LIS[i] = maxx;
  45. }
  46. maxx=-99;
  47. for(i=0;i<6*n;++i) {
  48. maxx = (maxx<LIS[i]) ? LIS[i]:maxx;
  49. }
  50. cout<<maxx<<"\n";
  51. block.clear();
  52. }
  53. return 0;
  54. }
Runtime error #stdin #stdout 0s 3620KB
stdin
25
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
stdout
Standard output is empty