Codeforces 429B Working out

Source: Internet
Author: User

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

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.