HDU 3377 (plug DP one loop fixed endpoint)

Source: Internet
Author: User

 

Plan

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 207 accepted submission (s): 54

Problem descriptionone day, resty comes to an incredible world to seek eve -- the origin of life. lilith, the sister of Eve, comes with him. although resty wants to find Eve as soon as possible, Lilith likes to play games so much that you can't make
Her make any move if you don't play with her.

Now they comes to the magical world and lilish ask resty to play with her.

The game is following:
Now the world is divided into a m * n grids by Lilith, And Lilith gives each grid a score.
So we can use a matrix to describe it.
You shoshould come from cell (0, 0) to cell (m-1, n-1) (up-left to down-right) and try to colloct as more score as possible.
According to lilish's rule, You can't arrive at each cell more than once.

Resty knows that lilish will be easy to find the max score, and he doesn' t want to lose the game.
So he want to find the game plan to reach the max score.

Your task is to calculate the max score that lilish will find, the map is so small so it shouldn't be difficult for you, right?

 

 

Inputthe input consists of more than one testdata.
Process to the end of data.
For each test data:
The first live give m and n. (1 <= m <= 8, 1 <= n <= 9)
Following M lines, each contain N number to give you the M * n matrix.
Each number in the matrix is between-2000 and 2000

 

Outputoutput format is "case ID: ANS" One Line for each data
Don't print any empty line to the output

 

Sample Input
2 21 23 13 30 -20 1001 -20 -201   1   1
 

 

Sample output
Case 1: 5Case 2: 61
 

 

Authorresty

 

Sourcehdoj monthly contest-2010.04.04

 

Recommendlcy

Analysis: This question is similar to that of the building instructor, but it can be accessed only in some cases, as long as the plug is not extended out of the plug, and the status transfer is changed to take the maximum value, then apply the template ~~~

Code:

# Include <cstdio> <br/> # include <cstring> <br/> using namespace STD; <br/> const int Mm = 15511; <br/> struct data <br/> {<br/> int s [mm], H [mm], p [mm], T, d [mm]; <br/> int Hash (int x, int dd) <br/>{< br/> int I, C = x % mm; <br/> for (I = H [c]; I> = 0; I = P [I]) <br/> If (s [I] = X) <br/>{< br/> If (DD> d [I]) d [I] = dd; <br/> return I; <br/>}< br/> S [T] = x, P [T] = H [c], H [c] = T, d [T] = dd; <br/> return t ++; <br/>}< br/> void clear () <br />{< Br/> T = 0, memset (H,-1, sizeof (h); <br/>}< br/>} f [2]; <br/> int I, j, G1, G2, U, k, n, m, a, B, A1, A2, B1, B2, G [13] [13]; <br/> int eat (int s, int A, int B, int C, bool F) <br/>{< br/> int n = 1, x; <br/> while (n) <br/>{< br/> If (f) A <= 2, B <= 2, c <= 2; <br/> else a> = 2, B> = 2, c >>=2; <br/> X = S & C; <br/> If (x = A) ++ N; <br/> If (x = B) -- N; <br/>}< br/> return (s ^ B) |; <br/>}< br/> void work (int s, int d) <br/>{< br/> int x, Y, DD = d + G [I] [J]; <br/> X = A & S, y = B & S; <br/> If (x = 0 & Y = 0) <br/> {<br/> If (I <n & J <m) f [G2]. hash (S | A1 | B2, DD); <br/> F [G2]. hash (S, d); <br/>}< br/> else if (x = 0 & Y = b1) <br/> {<br/> If (j <m) f [G2]. hash (S, DD); <br/> if (I <n) f [G2]. hash (s ^ B1) | A1, DD); <br/>}< br/> else if (x = A1 & Y = 0) <br/> {<br/> if (I <n) f [G2]. hash (S, DD); <br/> If (j <m) f [G2]. hash (s ^ A1) | B1, DD); <br/>}< br/> else if (x = A1 & Y = b1) f [G2]. has H (eat (s ^ A1 ^ B1, B1, B2, B, 1), DD); <br/> else if (x = 0 & Y = b2) <br/> {<br/> If (j <m) f [G2]. hash (S, DD); <br/> if (I <n) f [G2]. hash (s ^ B2) | A2, DD); <br/>}< br/> else if (x = a2 & Y = 0) <br/> {<br/> if (I <n) f [G2]. hash (S, DD); <br/> If (j <m) f [G2]. hash (s ^ A2) | B2, DD); <br/>}< br/> else if (x = a2 & Y = b2) f [G2]. hash (eat (s ^ A2 ^ B2, A2, A1, A, 0), DD); <br/> else if (x = a2 & Y = b1) f [G2]. hash (s ^ A2 ^ B1, DD); <br/>}< br/> int dp () <br/> {<Br/> int ans =-111111111; <br/> F [0]. clear (); <br/> F [0]. hash (1, 0); <br/> for (-- N, -- M, G1 = 1, G2 = I = 0; I <= N; ++ I) <br/> {<br/> for (k = 0; k <F [G2]. t; ++ K) f [G2]. s [k] <= 2; <br/> A = 3, B = 3 <2, a1 = 1, a2 = 2, b1 = 1 <2, b2 = 2 <2; <br/> for (j = 0; j <= m; A <= 2, B <= 2, A1 <= 2, a2 <= 2, B1 <= 2, b2 <= 2, ++ J) <br/> If (G [I] [J]) for (G1 =! G1, G2 =! G2, F [G2]. clear (), k = 0; k <F [G1]. t; ++ K) <br/>{< br/> if (I = N & J = m) <br/> {<br/> If (f [G1]. s [k] = b1 | f [G1]. s [k] = A1) & F [G1]. d [k]> ans) ans = f [G1]. d [k]; else continue; <br/>}< br/> Work (F [G1]. s [K], F [G1]. d [k]); <br/>}< br/> return ans + G [N] [m]; <br/>}< br/> int main () <br/>{< br/> int T = 0; <br/> while (scanf ("% d", & N, & M )! =-1) <br/>{< br/> for (I = 0; I <n; ++ I) <br/> for (j = 0; j <m; ++ J) scanf ("% d", & G [I] [J]); <br/> printf ("case % d: % d/N ", ++ T, dp (); <br/>}< br/> return 0; <br/>} 

 

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.