[HDU 2686] Matrix

Source: Internet
Author: User

On the Internet, the question is a charge flow.

I gave a rough look at the data Scope and thought that the topic seemed to make us look like "Big (d) Fart (p)". To respect the speaker, I 'd like to thank you ~

 

First, a loop can be seen as two steps in parallel. This is the common idea of big fart and Fei yongliu.

Therefore, we can use several diagonal lines (that is, the diagonal lines of x + y = K) to divide the status.

Consider enumerating two vertices on the diagonal line X1, Y1, X2, Y2
We strongly use F [X1] [Y1] [X2] [y2] to express the best solution for the two paths to go to points (x1, Y1) and points (X2, Y2) respectively.

In this way, F [X1] [Y1] [X2] [y2] can be composed of F [x1-1] [Y1] [x2-1] [y2], f [x1-1] [Y1] [X2] [y2-1], F [X1] [y1-1] [x2-1] [y2], f [X1] [y1-1] [X2] [y2-1] To get (crazy)

And when the points (x1, Y1) and points (X2, Y2) are adjacent on the diagonal line, it is special because the points (x1-1, Y1) and the points (X2, y2-1) overlap, special considerations (really sad)

 

Although it looks disgusting, I think it is also a big advantage to say that the short stream is so short?

 

#include <cstdio>#include <cstring>#define max(x, y) ((x)>(y) ? (x):(y))const int size=32;int n;int a[size][size];int f[size][size][size][size];inline int getint();inline void putint(int);int main(){while (scanf("%d", &n)!=EOF){for (int i=1;i<=n;i++)for (int j=1;j<=n;j++)a[i][j]=getint();memset(f, 0, sizeof f);f[2][1][1][2]=a[1][1]+a[1][2]+a[2][1];for (int i=4;i<2*n;i++)for (int y1=i<=n+1?1:i-n;y1<i-1 && y1<n;y1++)for (int y2=y1+1;y2<i && y2<=n;y2++){int x1=i-y1, x2=i-y2;if (y2-y1==1) f[x1][y1][x2][y2]=max(max(f[x1][y1-1][x2][y1], f[x2][y1][x2-1][y2]), f[x1][y1-1][x2-1][y2]);else f[x1][y1][x2][y2]=max(max(f[x1-1][y1][x2-1][y2], f[x1-1][y1][x2][y2-1]), max(f[x1][y1-1][x2-1][y2], f[x1][y1-1][x2][y2-1]));f[x1][y1][x2][y2]+=a[x1][y1]+a[x2][y2];}putint(a[n][n]+f[n][n-1][n-1][n]);}return 0;}inline int getint(){register int num=0;register char ch;do ch=getchar(); while (ch<‘0‘ || ch>‘9‘);do num=num*10+ch-‘0‘, ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘);return num;}inline void putint(int num){char stack[15];register int top=0;for ( ;num;num/=10) stack[++top]=num%10+‘0‘;for ( ;top;top--) putchar(stack[top]);putchar(‘\n‘);}

 

[HDU 2686] Matrix

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.