|
| 1 | +#include <cstdio> |
| 2 | +#include <iomanip> |
| 3 | +#include <cstring> |
| 4 | +#include <cmath> |
| 5 | +#include <cstdlib> |
| 6 | +#include <cctype> |
| 7 | +#include <algorithm> |
| 8 | +#include <string> |
| 9 | +#include <vector> |
| 10 | +#include <queue> |
| 11 | +#include <map> |
| 12 | +#include <set> |
| 13 | +#include <sstream> |
| 14 | +#include <stack> |
| 15 | +#include <list> |
| 16 | +#include <iostream> |
| 17 | +#include <assert.h> |
| 18 | + |
| 19 | +#define mem(x,y) memset(x,y,sizeof(x)) |
| 20 | +#define CLEAR(x) memset(x,0,sizeof(x)) |
| 21 | + |
| 22 | +#define pb push_back |
| 23 | +#define Sort(v) sort(v.begin(),v.end()) |
| 24 | +#define _sort(s, n) sort(s, s+n) |
| 25 | +#define sqr(x) ((x)*(x)) |
| 26 | + |
| 27 | +#define le 50001 |
| 28 | +#define ERR 1e-9 |
| 29 | +#define pi (2*acos(0)) |
| 30 | +#define PI 3.141592653589793 |
| 31 | +#define MX 1e18 |
| 32 | + |
| 33 | +#define scanint(a) scanf("%d", &a) |
| 34 | +#define scanLLD(a) scanf("%lld", &a) |
| 35 | + |
| 36 | +typedef long long ll; |
| 37 | +using namespace std; |
| 38 | + |
| 39 | +/* -------------------------- */ |
| 40 | + |
| 41 | +int gold[10000][10000]; |
| 42 | +int dp[10000][10000]; |
| 43 | + |
| 44 | +int getMaxGold(int m, int n) { |
| 45 | + for (int i = 0; i < m; dp[i][0] = gold[i][0], i++); |
| 46 | + for (int i = 1; i < m; i++) { |
| 47 | + for (int j = 0; j < n; j++) { |
| 48 | + int right = dp[j][i-1]; |
| 49 | + int rightUP = (i == 0) ? 0 : dp[j-1][i-1]; |
| 50 | + int rightDN = (i == m-1) ? 0 : dp[j+1][i-1]; |
| 51 | + dp[j][i] = gold[j][i] + max(right, max(rightUP, rightDN)); |
| 52 | + } |
| 53 | + } |
| 54 | + int sol = dp[m-1][n-1]; |
| 55 | + for (int i = 0; i < m; sol = max(sol, dp[i][n-1]), i++); |
| 56 | + return sol; |
| 57 | +} |
| 58 | + |
| 59 | +int main() { |
| 60 | + int m, n, x; |
| 61 | + scanf("%d %d", &m, &n); |
| 62 | + for (int i = 0; i < m; i++) |
| 63 | + for (int j = 0; j < n; scanint(gold[i][j]), j++); |
| 64 | + cout << getMaxGold(m, n) << endl; |
| 65 | +} |
| 66 | + |
| 67 | +/********* |
| 68 | +4 4 |
| 69 | +1 3 1 5 |
| 70 | +2 2 4 1 |
| 71 | +5 0 2 3 |
| 72 | +0 6 1 2 |
| 73 | + |
| 74 | + == 16 |
| 75 | + ********/ |
0 commit comments