Recursive DP UVA 1366 Martian Mining

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.