fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MaxN = 102;
  4. int n, a[MaxN], b[MaxN], g[MaxN], dp[MaxN], ans;
  5.  
  6. int solve(int i) {
  7. if(dp[i] != -1) {
  8. return dp[i];
  9. }
  10. dp[i] = g[i];
  11. for(int j = 0; j < n; j ++) {
  12. if(j == i) continue;
  13. if((a[i] >= a[j] && b[i] >= b[j]) || (a[i] >= b[j] && b[i] >= a[j])) {
  14. dp[i] = max(dp[i], g[i] + solve(j));
  15. }
  16. }
  17. return dp[i];
  18. }
  19.  
  20. int main() {
  21. ios_base::sync_with_stdio(0);cin.tie(0);
  22. cin >> n;
  23. for(int i = 0; i <n; i ++) {
  24. cin >> a[i] >> b[i] >> g[i];
  25. dp[i] = -1;
  26. }
  27. ans = 0;
  28. for(int i = 0; i < n; i ++) {
  29. ans = max(ans, solve(i));
  30. }
  31. cout << ans;
  32. }
  33.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty