hiho Week 5 register

Ended

Participants:445

Verdict:Accepted
Score:100 / 100
Submitted:2014-08-03 13:21:09

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 210;
int dp[MAXN][MAXN];
int a[MAXN][MAXN];
int T;
int dfs(int i,int j) {
    if (dp[i][j]) return dp[i][j];
    if (i == T) return 0;
    return dp[i][j] = max(dfs(i+1,j),dfs(i+1,j+1)) + a[i][j];
}
int main () {
    cin >> T;
    for (int i = 0;i < T;i++) {
        for (int j = 0;j < i+1;j++) {
            cin >> a[i][j];
        }
    }
    cout << dfs(0,0) << endl;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX