Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: yuhung91
- TASK: numtri
- LANG: C++
- */
- #pragma GCC optimzize("Ofast,no-stack-protector")
- #include<bits/stdc++.h>
- #define int long long
- #define quick ios::sync_with_stdio(0);cin.tie(0);
- #define rep(x,a,b) for(int x=a;x<=b;x++)
- #define repd(x,a,b) for(int x=a;x>=b;x--)
- #define lowbit(x) (x&-x)
- #define sz(x) (int)(x.size())
- #define F first
- #define S second
- #define all(x) x.begin(),x.end()
- #define mp make_pair
- #define eb emplace_back
- using namespace std;
- typedef pair<int,int> pii;
- void debug(){
- cout<<"\n";
- }
- template <class T,class ... U >
- void debug(T a, U ... b){
- cout<<a<<" ",debug(b...);
- }
- const int N=1e3+7;
- int x[N][N];
- int dp[N][N];
- const int INF=1e18;
- signed main(){
- quick
- ifstream cin("numtri.in");ofstream cout("numtri.out");
- int n;
- cin>>n;
- rep(i,1,n){
- rep(j,1,i) cin>>x[i][j];
- }
- rep(i,1,n){
- rep(j,1,i){
- dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+x[i][j];
- }
- }
- int ans=0;
- rep(i,1,n){
- ans=max(ans,dp[n][i]);
- }
- cout<<ans<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement