Bzoj 2310:PARKII__ Plug DP

Source: Internet
Author: User
The following:

Ask for a path so that each point passes at most once and the sum of the weights is the largest. The puzzle :

A plug DP with a separate plug.
The puzzle is well written and the various situations are analyzed concretely.
I've been trying to spit out the code for a day.
In addition to a variety of hand-base errors to be aware of, when the two separate plugs, there is no other plug to update the answer.

#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std;
const INT mod=1000037,inf=1<<30;
int list[2][mod],state[2][mod],hash[mod],num[2],now,ans=-inf;
int map[110][10],n,m; int get (int s,int p) {return (s>> (p-1) *2) &3;} void Change (int &s,int p,int c) {S^=get) << ((s,p) *
2);s^=c<< ((p-1) *2);} void update (int &x,int y) {x=x>y?x:y} int find (int st,int c) {int ans=0;for (int i=1;i<=m+1;i++) ans+= (
    St,i) ==c);
return ans;
    } void Add (int st,int sum) {int s=st%mod;
    while (hash[s]&&list[now][hash[s]]!=st) (s+=1)%=mod;
    if (!hash[s]) hash[s]=++num[now],list[now][num[now]]=st,state[now][num[now]]=sum;
else update (state[now][hash[s]],sum);
    int find_2 (int st,int j,int c) {int top=c;
        for (int i=j;i<=m+1;i++) {int tmp=get (st,i); if (tmp==1) top++;if (tmp==2) top--;
    if (!top) return i; an int find_1 (int st,int j,int c) {int TOp=c;
        for (int i=j;i;i--) {int tmp=get (st,i); if (tmp==2) top++;if (tmp==1) top--;
    if (!top) return i;
    } void Change_3 (int &st,int j) {int pos;
    if (Get (st,j) ==1) pos=find_2 (st,j+1,1);
    if (Get (st,j) ==2) pos=find_1 (st,j-1,1);
Change (st,pos,3);
    } void Solve () {num[0]=1;state[0][1]=list[0][1]=now=0; for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {Now^=1;num[now]=0;memset (hash,0,size
            Of (hash)); for (int k=1;k<=num[!now];k++) {int st=list[!now][k],p=get (ST,J), Q=get (st,j+1), sum=state[!n
                OW][K];
                    if (!p&&!q) {int st1=st;
                    Add (st,sum);
                    if (j+1<=m&&i+1<=n) change (st,j,1), change (st,j+1,2), add (st,sum+map[i][j));
                    St=st1; if (Find (st,3) <2) {if (i+1<)=n) Change (st,j,3), add (St,sum+map[i][j]), st=st1;
                    if (j+1<=m) change (st,j+1,3), add (St,sum+map[i][j]);
                    } else if (!p&&q) {int st1=st;
                    if (Q==3&&find (st,3) ==1&&find (st,1) ==0) update (ANS,SUM+MAP[I][J));
                    if (j+1<=m) Add (St,sum+map[i][j]);
                    if (i+1<=n) change (st,j,q), change (st,j+1,0), add (st,sum+map[i][j));
                St=st1;if (Q!=3&&find (st,3) <2) change_3 (st,j+1), change (st,j+1,0), add (st,sum+map[i][j));
                    else if (p&&!q) {int st1=st;
                    if (P==3&&find (st,3) ==1&&find (st,1) ==0) update (ANS,SUM+MAP[I][J));
                    if (i+1<=n) Add (St,sum+map[i][j]);
                    if (j+1<=m) change (st,j,0), change (st,j+1,p), add (st,sum+map[i][j)); st=St1;if (P!=3&&find (st,3) <2) change_3 (st,j), change (st,j,0), add (st,sum+map[i][j));
                else if (p==3&&q==3) {if (st,3) ==2&&find (st,1) ==0) update (ANS,SUM+MAP[I][J);}
                else if (p==2&&q==1) {change (st,j,0), change (st,j+1,0), add (St,sum+map[i][j]); else if (p==1&&q==1) {change (st,j,0); change (st,j+1,0); Change (St,find_2 (st,j+2,1), 1); Add (ST,SUM+MAP[I][J))
                ;} else if (p==2&&q==2) {change (st,j,0); change (st,j+1,0); Change (St,find_1 (st,j-1,1), 2); Add (ST,SUM+MAP[I][J))
                ;}
                else if (p==3&&q&&q!=3) {change_3 (st,j+1), change (st,j,0), change (st,j+1,0), add (st,sum+map[i][j));
            else if (q==3&&p&&p!=3) {change_3 (st,j), change (st,j,0), change (st,j+1,0), add (st,sum+map[i][j));
    for (int j=1;j<=num[now];j++) list[now][j]<<=2;
    the int main () {scanf ("%d%d", &n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf ("%d", &map[i][j)), Ans=max (ans,map[i][j));
Solve ();p rintf ("%d", ans); }

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.