"Fzu" 1977 Pandora Adventure

Source: Internet
Author: User
Tags define get

http://acm.fzu.edu.cn/problem.php?pid=1977

Test instructions: Nxm grid, there are 3 kinds of lattice, ' O ' must Pass, ' * ' can choose to pass, ' X ' cannot pass. Now requires that the path passes through all ' O ' and is the number of simple loops

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef long ll; struct H {static const int m=799997;struct E {int next, to;} E[m];int Ihead, CNT, Hash[m];ll sum[m]; H () {ihead=cnt=0; memset (hash,-1, sizeof hash); memset (sum, 0, sizeof sum);} BOOL Find (int x, int &pos) {pos=x%m;while (1) {if (hash[pos]==x) return False, if (hash[pos]==-1) break; ++pos; if (pos== M) pos=0; }hash[pos]=x; return true;} void ins (int a, ll b) {int pos; if (!find (A, POS)) {sum[pos]+=b; return;} E[++cnt].next=ihead; ihead=cnt; E[cnt].to=pos; Sum[pos]=b;} void CLR () {for (int i=ihead; i; i=e[i].next) hash[e[i].to]=-1, sum[e[i].to]=0; ihead=cnt=0;}} T1, T2; #define BIT (b) ((a) << ((b) <<1)) #define The CLR (A, a) (A^= ((a) &bit (3,b))) #define GET (A, B) (3& ( A) >> ((b) <<1))) const int N=15;int N, M, All;ll ans;int mp[n][n];int Find (int s, int col, int flag) {int Sum=0;i F (flag) {for (int i=col; i<=m; ++i) {int K=get (s, i); if (k==1) ++sum;if (k==2)--sum;if (!sum) return i;} else {for (int i=col; i>=0;-I.) {int K=get (s, i), if (k==1)--sum;if (k==2) ++sum;if (!sum) return i;}} return-1;} void print (int s) {for (int i=0; i<=m; ++i) {int K=get (s, i), if (k==0) Putchar (' # '), else if (k==1) Putchar (' ('); else I  F (k==2) Putchar (') '); }puts ("");} #define F puts ("error"), bool Next (int s, int row, int col, bool U, BOOL D, BOOL L, bool R, int &t) {if (row==n-1&& AMP;D) | | (row==0&&u) | | (Col==m-1&&r) | | (col==0&&l)) Return 0;if ((D&&!mp[row+1][col]) | | (R&&!mp[row][col+1])) Return 0;int L=get (S, col), U=get (S, col+1), Flag=get (S, m+1), D=0, R=0;if ((l&&! L) | | (!l&&l) | | (u&&! U) | | (!u&&u)) return 0;//printf ("state:"); print (s);//printf ("row:%d, col:%d, u:%d, d:%d, l:%d, r:%d", Row, col, U, D, L, R);//printf ("Left:"); if (l==1) printf ("("); if (l==2) printf (")"); if (l==0) printf ("#");//printf ("UPTP:"); if (u==1) printf ("("); if (u==2) printf (")"); if (u==0) printf ("#"); Puts (""); t=s; CLR (T, col); CLR (t, col+1), if (!l &&!u) {if (R && D) d=1, r=2;} else if (l && u) {if (l==1 && u==1) {int Pos=find (s, col+1, 1); CLR (T, POS); T|=bit (1, POS);} else if (l==2 && u==2) {int Pos=find (s, col, 0); CLR (T, POS); T|=bit (2, POS);} else if (l==1 && u==2) flag=1;} else if (l &&!u) {if (D) d=l, R=0;if (R) d=0, R=l;} else if (!l && u) {if (D) D=u, R=0;if (R) d=0, R=u;} T|=bit (d, Col); T|=bit (R, col+1); if (col==m-1) t<<=2;  Puts ("=============\nnext"); Print (t); t&=all;if (flag) t|=bit (1, m+1); return 1;} void BFs () {H *q1, *q2;q1=&t1; q2=&t2;q1->clr (); q2->clr (); q1->ins (0, 1); for (int row=0; row<n; ++row ) for (int col=0; col<m; ++col) {q2->clr ();//printf ("q1->cnt:%d\n", q1->cnt); for (int i=q1->ihead; i; i= Q1->e[i].next) {int s=q1->hash[q1->e[i].to], T, Flag=get (S, m+1);//print (s); ll Sum=q1->sum[q1->e[i]. To];if (mp[row][col]==2 && flag) continue;if (mp[row][col]<=1) {if (next (S, Row, col, 0, 0, 0, 0, T)) q2->ins (t, sum);} if (mp[row][col]>=1 &&!flag) {//Forgot to award flag again for a long time ... if (next (S, Row, col, 1, 1, 0, 0, T)) q2->ins (t, sum); if (next (s, Row, col, 1, 0, 1, 0, T)) Q2->ins (t, sum), if (next (S, Row, col, 1, 0, 0, 1, t)) q2->ins (t, sum), if (next (S, Row, col, 0, 1, 1, 0, T)) Q2->ins (t, sum), if (next (S, Row, col, 0, 1, 0, 1, t)) q2->ins (t, sum), if (next (S, Row, col, 0, 0, 1, 1, T)) q2->ins (t, sum);} }swap (Q1, Q2);} for (int i=q1->ihead; i; i=q1->e[i].next) ans+=q1->sum[q1->e[i].to];} int main () {int cs; scanf ("%d", &cs), char s[n];for (int cc=1; cc<=cs; ++cc) {ans=0;scanf ("%d%d", &n, &m); al L=bit (1, m+1) -1;for (int i=0; i<n; ++i) {scanf ("%s", s), for (int j=0; j<m; ++j) {if (s[j]== ' * ') mp[i][j]=1;else if (S[j] = = ' O ') Mp[i][j]=2;else mp[i][j]=0;}} BFS ();p rintf ("Case%d:%i64d\n", CC, ans);} return 0;}

  

Today, the ability to commit to Max?

There is no need to consider the situation is not necessary to expand the status Qaq

The topic is actually a template problem. It's just that we don't know where the ring is linked, so let's open another State to indicate whether the current contour is already a ring.

"Fzu" 1977 Pandora Adventure

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.