#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; #define INF 0x7fffffff #define INPUT freopen("d:\\in.txt", "r", stdin); #define OUTPUT freopen("d:\\out.txt", "w", stdout); #define N 20 int mp[N][N]; int d[N][N]; int m, n; int dp(int i, int j) { if(i<0 || j<0 || i>=m || j>=n) return 0; if(d[i][j] > 0) return d[i][j]; return d[i][j] += max(dp(i, j-1), dp(i-1, j))+mp[i][j]; } int main() { //INPUT; while(~scanf("%d%d", &m, &n)) { for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ scanf("%d", &mp[i][j]); } } memset(d, 0, sizeof(d)); printf("%d\n", dp(m-1, n-1)); } return 0; }
时间: 2024-10-02 19:14:06