Guest User

Untitled

a guest
Feb 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string.h>
  4. using namespace std;
  5. struct block {
  6. int len, wid;
  7. } arr[100];
  8. int W[100], in[100];
  9. vector<int> G[100];
  10. bool operator < (block x, block y) {
  11. return ((x.len < y.len && x.wid < y.wid) || (x.len < y.wid && x.wid < y.len));
  12. }
  13. int dfs(int x) {
  14. int sum = 0;
  15. for ( int i : G[x] )
  16. sum = max(sum,dfs(i));
  17. return W[x]+sum;
  18. }
  19. int main() {
  20. ios::sync_with_stdio(0);
  21. cin.tie(0);
  22. int n, a, b, c, t = 1;
  23. while ( cin >> n && n ) {
  24. int cnt = 0;
  25. memset(G,0,sizeof(G));
  26. memset(W,0,sizeof(W));
  27. memset(in,0,sizeof(in));
  28. for ( int i=0; i<n; ++i ) {
  29. cin >> a >> b >> c;
  30. W[cnt] = c; arr[cnt++] = {a,b};
  31. W[cnt] = b; arr[cnt++] = {a,c};
  32. W[cnt] = a; arr[cnt++] = {b,c};
  33. }
  34. for ( int i=0; i<cnt; ++i )
  35. for ( int j=0; j<cnt; ++j )
  36. if ( arr[i] < arr[j] ) {
  37. G[i].emplace_back(j);
  38. in[j]++;
  39. }
  40. int ans = 0;
  41. for ( int i=0; i<cnt; ++i )
  42. if ( in[i] == 0 )
  43. ans = max(ans,dfs(i));
  44. cout << "Case " << t++ << ": maximum height = " << ans << '\n';
  45. }
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment