Topic Portal
1 /*2 Test Instructions: Abstract point is to give two matrices, overlapping (that is, they choose one), two paving: from right to left and from bottom to top, halfway can not turn,3 after reaching the boundary, add the weights along the way to maximize4 DP: This is a word recursive problem, first I read the topic long time, read and write the prefix and do not know how to define the state of good, can not write the state transfer equation, too weak. 5 Dp[i][j] Indicates the maximum value obtained with (I, j) for the lower right corner, the state transition equation: dp[i][j] = max (Dp[i-1][j] + sum1[i][j], dp[i][j-1] + sum2[i][j]); SUM1 represents the prefix of the column, sum2 represents the prefix of the row6 */7 /************************************************8 * Author:running_time9 * Created time:2015-8-9 10:18:37Ten * File Name:UVA_1366.cpp One ************************************************/ A -#include <cstdio> -#include <algorithm> the#include <iostream> -#include <sstream> -#include <cstring> -#include <cmath> +#include <string> -#include <vector> +#include <queue> A#include <deque> at#include <stack> -#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> in#include <ctime> - using namespacestd; to + #defineLson L, Mid, RT << 1 - #defineRson mid + 1, R, RT << 1 | 1 thetypedefLong Longll; * Const intMAXN = 5e2 +Ten; $ Const intINF =0x3f3f3f3f;Panax Notoginseng Const intMOD = 1e9 +7; - intA[MAXN][MAXN], B[MAXN][MAXN]; the intSUM1[MAXN][MAXN], SUM2[MAXN][MAXN]; + intDP[MAXN][MAXN]; A the intMainvoid) {//UVA 1366 Martian Mining + intN, M; - while(SCANF ("%d%d", &n, &m) = =2) { $ if(!n &&!m) Break; $memset (SUM1,0,sizeof(SUM1)); - for(intI=1; i<=n; ++i) { - for(intj=1; j<=m; ++j) { thescanf ("%d", &a[i][j]); SUM1[I][J] = sum1[i][j-1] +A[i][j]; - }Wuyi } thememset (sum2,0,sizeof(sum2)); - for(intI=1; i<=n; ++i) { Wu for(intj=1; j<=m; ++j) { -scanf ("%d", &b[i][j]); SUM2[I][J] = sum2[i-1][J] +B[i][j]; About } $ } -Memset (DP,0,sizeof(DP)); - for(intI=1; i<=n; ++i) { - for(intj=1; j<=m; ++j) { ADP[I][J] = max (dp[i-1][J] + sum1[i][j], dp[i][j-1] +sum2[i][j]); + } the } -printf ("%d\n", Dp[n][m]); $ } the the return 0; the}
Recursive DP UVA 1366 Martian Mining