Test instructions: Matrix A line from top left to bottom right, a top right to bottom left, there can only be one intersection, and the intersection value is not counted, ask you how much value you can get.
Problem Solving ideas: First find out four matrices, and then enumerate the points and the way to enter the point, where the DP problem requires special consideration of the boundary.
Problem Solving Code:
1 //File name:429b.cpp2 //Author:darkdream3 //Created time:2015 March 08 Sunday 10:13 53 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - using namespacestd; - inta[1005][1005]; - intldp[1005][1005]; - intrdp[1005][1005]; in intudp[1005][1005]; - intddp[1005][1005]; to intMain () { + intN, M; -scanf"%d%d",&n,&m); the for(inti =1; I <= N;i + +) * for(intj =1; J <= M;j + +) $scanf"%d",&a[i][j]);Panax Notoginseng for(inti =1; I <= N;i + +) - { the for(intj =1; J <= M;j + +) + { ALDP[I][J] = A[i][j] + max (ldp[i][j-1],ldp[i-1][j]); the } + } - for(inti = N;i >=1; I--) $ { $ for(intj =1; J <= M;j + +) - { -RDP[I][J] = A[i][j] + max (rdp[i][j-1],rdp[i+1][j]); the } - }Wuyi for(inti = N;i >=1; I--) the { - for(intj = M;j >=1; J--) Wu { -UDP[I][J] = A[i][j] + max (udp[i][j+1],udp[i+1][j]); About } $ } - for(inti =1; I <= N;i + +) - { - for(intj = m; J >=1; J--) A { +DDP[I][J] = A[i][j] + max (ddp[i][j+1],ddp[i-1][j]); the } - } $ intsum =0 ; the for(inti =2; i < N;i + +) the for(intj =2; J < M;j + +) the { the intTsum =sum; -sum = max (sum,ldp[i-1][J] + udp[i+1][J] + rdp[i][j-1] + ddp[i][j+1]) ; insum = max (sum,rdp[i+1][J] + ddp[i-1][J] + ldp[i][j-1] + udp[i][j+1]) ; the } theprintf"%d\n", sum); About return 0; the}
View Code
Codeforces 429B Working out