HDU 4113 Construct the Great Wall (plug dp)

Source: Internet
Author: User

For a long time, I didn't know what the dp plug looks like. At first, I thought it was a plug, a plug, an unlimited number of errors.

I saw this question yesterday.

Baidu later found that no question was answered, neither hust nor hdu was discuss... I found a rare topic on the acm-icpc information site. But after seeing the plug, the code did not look at it because of its style. I thought for a long time and figured it out. Then, the code will not be sent until today ....

 

If you think of a point as a grid, you can achieve it without restrictions such as public points and public edges, and obviously it is the model of the shortest single loop of the plug dp. This is a difficult question (this was due to the fact that the question requires the calculation of the shortest perimeter. Obviously, this modeling is easy to solve)

Another difficulty is how to ensure the location where OOXX is located, that is, the requirement of the subject. O is inside the single loop, and X is outside the single loop. My approach is to mark and add one-dimensional 01 to indicate whether the upper-left vertex of the current intersection is inside. During the transfer process, check whether the subsequent status is OK.

This question needs to be matched by parentheses. It is clear that a hash table is used instead of an array...

Although it took a long time, 1A still feels good.

 

Suggested drawing (in fact, we recommend drawing all the plug dp for ease of analysis, and will not occupy the computer pit teammates)

# Include <cstdio> # include <cstring> # include <iostream> # include <string> # include <algorithm> # include <cmath> # include <queue> # include <vector> # include <set> # include <map> using namespace std; # define inf 0x3f3f3f # define eps 1e-8 # define ll long # define maxm 51000 # define STATE 510000 # define HASH 10007 # define maxd 15int n, m; char maze [maxd] [maxd]; int code [maxd]; struct HASHMAP {int head [HASH], nxt [STATE ], Sz; int state [STATE], f [STATE]; void clear () {sz = 0; memset (head,-1, sizeof (head ));} void push (int st, int ans) {int h = st % HASH; for (int I = head [h]; I! =-1; I = nxt [I]) {if (st = state [I]) {f [I] = min (f [I], ans ); return ;}} state [sz] = st, f [sz] = ans, nxt [sz] = head [h]; head [h] = sz ++ ;}} hm [2] [2]; void decode (int st) {for (int I = 0; I <= m; ++ I) code [I] = st & 3, st> = 2;} int encode () {int ret = 0; for (int I = m; I> = 0; -- I) ret = ret <2 | code [I]; return ret;} bool jud (int I, int j, int in) {if (maze [I] [j] = 'O') return in; if (maze [I] [j] = 'x') return! In; return true;} int edx, edy; int ans; void dp (int I, int j, int cur, int in) {int xo = (1 <(j * 2); int ox = (2 <(j * 2); int oo = xo | ox; int mv = (j = m? 2: 0); for (int k = 0; k 

 

HDU 4113 Construct the Great Wall (plug dp)

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.