Advertisement
yuhung94

Untitled

Nov 16th, 2022
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. /*
  2. ID: yuhung91
  3. TASK: numtri
  4. LANG: C++                
  5. */
  6. #pragma GCC optimzize("Ofast,no-stack-protector")
  7. #include<bits/stdc++.h>
  8. #define int long long
  9. #define quick ios::sync_with_stdio(0);cin.tie(0);
  10. #define rep(x,a,b) for(int x=a;x<=b;x++)
  11. #define repd(x,a,b) for(int x=a;x>=b;x--)
  12. #define lowbit(x) (x&-x)
  13. #define sz(x) (int)(x.size())
  14. #define F first
  15. #define S second
  16. #define all(x) x.begin(),x.end()
  17. #define mp make_pair
  18. #define eb emplace_back
  19. using namespace std;
  20. typedef pair<int,int> pii;
  21. void debug(){
  22.     cout<<"\n";
  23. }
  24. template <class T,class ... U >
  25. void debug(T a, U ... b){
  26.     cout<<a<<" ",debug(b...);
  27. }
  28. const int N=1e3+7;
  29. int x[N][N];
  30. int dp[N][N];
  31. const int INF=1e18;
  32. signed main(){
  33.     quick
  34.     ifstream cin("numtri.in");ofstream cout("numtri.out");
  35.     int n;
  36.     cin>>n;
  37.     rep(i,1,n){
  38.         rep(j,1,i) cin>>x[i][j];
  39.     }
  40.     rep(i,1,n){
  41.         rep(j,1,i){
  42.             dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+x[i][j];
  43.         }
  44.     }
  45.     int ans=0;
  46.     rep(i,1,n){
  47.         ans=max(ans,dp[n][i]);
  48.     }
  49.     cout<<ans<<"\n";
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement