Created
March 20, 2018 17:31
-
-
Save fredbr/a87dafa945ae9a0475920aa4059a2f58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int maxn = 110; | |
int v[maxn][maxn]; | |
int dp[maxn][maxn]; | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
int n; | |
cin >> n; | |
for (int i = 1; i <= n; i++) { | |
for (int j = 1; j <= i; j++) cin >> v[i][j]; | |
} | |
for (int i = 1; i <= n; i++) dp[n][i] = v[n][i]; | |
for (int i = n-1; i >= 1; i--) { | |
for (int j = 1; j <= i; j++) { | |
dp[i][j] = v[i][j] + max(dp[i+1][j], dp[i+1][j+1]); | |
} | |
} | |
cout << dp[1][1] << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment