Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int input(){
- int res = 0; char c = ' ';
- while (c < '0') c = getchar();
- while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
- return res;
- }
- const int N = 1e3 + 1;
- int a[N][N], n;
- int main(){
- while (cin >> n){
- int ans = 0;
- for (int i = 1; i <= n; ++ i)
- for (int j = 1; j <= i; ++ j)
- a[i][j] = max(a[i - 1][j], a[i - 1][j - 1]) + input();
- for (int j = 1; j <= n; ++ j)
- ans = max(ans, a[n][j]);
- for (int i = 1; i <= n; ++ i)
- for (int j = 1; j <= i; ++ j)
- a[i][j] = 0;
- cout << ans << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement