Atitit.android Simulator Usage Report

Source: Internet
Author: User

It's a shame to get up late today and waste some time.

In the afternoon for the school game out of two questions, so far, the school race of the four questions have been completed. Another check, no errors, waiting for tomorrow's summary of ~.

The topic of AC automata was brushed three today, or the previous goal was not completed. Now VJ also can't get in, want to all night, don't give chance ~ ~

It is not a good habit to wait until tomorrow to finish the painting.

----------------------------------------------------------------------------------------------------------

1,hdu-4511- Xiao Ming series Story--the test of girlfriend

Rob the CZ FB, the heart is very happy, haha

AC automata More and more templates, the first to create an illegal path of the automaton. Then the tree asks for the shortest 1 to n points. I did not pay attention to " only go to the place where the current point number is larger ," the condition, the wrong n times, sad.

#include <stdio.h> #include <algorithm> #include <iostream> #include <stdlib.h> #include < vector> #include <queue> #include <string.h> #include <math.h>using namespace std; #define LL __ Int64#define maxn 55const int maxnode=110*5;const int childnum=55;const int Mod=1000000007;const int inf=99999999;struct    list{double X; Double y;}    node[maxn];struct listt{int p;    int t;    Double dis;    friend BOOL operator < (const LISTT &a,const listt &b) {return a.dis>b.dis;    }}pp,qq;double Dist (int x,int y) {double xx,yy;    xx=node[x].x-node[y].x;    YY=NODE[X].Y-NODE[Y].Y;    Double sum=xx*xx+yy*yy; Return 1.0*sqrt (1.0*sum);}    priority_queue<listt>que;struct ac_tree{int Chd[maxnode][childnum];    int Val[maxnode];    int Fail[maxnode];    int key[1<<11];    int Q[maxnode];    int id[128];    int sz;    int Vis[maxn][maxnode];        void Init () {fail[0]=0;       for (int i=0;i<childnum;i++) {id[i]=i;        }} void Reset () {memset (chd,0,sizeof (CHD));    Sz=1;        } void Insert (Vector<int>vec,int k) {int p=0;        int len=vec.size ();            for (int i=0;i<len;i++) {int c=id[vec[i]];                if (!chd[p][c]) {memset (chd[sz],0,sizeof (Chd[sz]));                val[sz]=0;            chd[p][c]=sz++;        } P=chd[p][c];    } val[p]=k;        } void Ac_build () {int *s=q,*e=q;                for (int i=1;i<childnum;i++) {if (Chd[0][i]) {fail[chd[0][i]]=0;            *e++=chd[0][i];            }} while (s!=e) {int u=*s++;            if (Val[fail[u]]) val[u]+=val[fail[u]];                for (int i=1;i<childnum;i++) {int &v=chd[u][i];                    if (v) {*e++=v; Fail[v]=chd[fail[u]][i];                Val[v]= (Val[v]+val[fail[v]);            } else v=chd[fail[u]][i];        }}} int word (int n) {while (!que.empty ()) Que.pop ();        memset (vis,0,sizeof (VIS));        Pp.p=1;        PP.T=CHD[0][1];        pp.dis=0.0;        Que.push (PP);        int CR;        Vis[1][pp.t]=1;            while (!que.empty ()) {pp=que.top ();          Que.pop ();           cout<< "____________" <<endl;            cout<<pp.p<<endl;                if (pp.p==n) {printf ("%.2f\n", Pp.dis);            return 0;                } for (int i=pp.p+1;i<=n;i++) {cr=chd[pp.t][i];                if (I==PP.P) continue;                if (VAL[CR]) continue;               if (VIS[I][CR]) continue;                cout<<pp.p<< "" <<i<< "" <<cr<<endl;                Vis[i][cr]=1;                Qq.p=i; SqlT=CR;                Qq.dis=1.0*pp.dis+1.0*dist (PP.P,QQ.P);            Que.push (QQ); }} cout<< "Can not be reached!"    <<endl;    }}ac;char Temp[155];int Main () {ac.init ();    int n,m,k,x;    int T; while (~SCANF ("%d%d", &n,&m)) {if (!) ( n| |        m)) break;        for (int i=1;i<=n;i++) {scanf ("%lf%lf", &node[i].x,&node[i].y);        } ac.reset ();        vector<int>vec;            for (int i=1;i<=m;i++) {vec.clear ();            scanf ("%d", &k);                while (k--) {scanf ("%d", &x);            Vec.push_back (x);        } ac.insert (vec,1);        } ac.ac_build ();    Ac.word (n); } return 0;}

2,hdu-4758-Walk Through Squares

1. On the automaton each state dp,dp[a][b][c][d] means that after a character, matching B R, in C this state, D is 4 binary number, indicating whether the string 1 and string 2

That is, a tree DP, think of a good state transfer equation is good.

#include <stdio.h> #include <algorithm> #include <iostream> #include <stdlib.h> #include < string.h>using namespace std; #define LL intconst int maxnode=101*2;const int childnum=2;const int mod=1000000007;    const int inf=99999999;struct ac_tree{int chd[maxnode][childnum];    int Val[maxnode];    int Fail[maxnode];    int key[1<<11];    int Q[maxnode];    int id[128];    int sz;    int dp[104][104][maxnode][4];        void Init () {fail[0]=0;        for (int i=0;i<childnum;i++) {id[i+ ' a ']=i;    } id[' R ']=0;id[' D ']=1;        } void Reset () {memset (chd,0,sizeof (CHD));    Sz=1;        } void Insert (char str[],int k) {int p=0;        int Len=strlen (str);            for (int i=0;i<len;i++) {int c=id[str[i]];                if (!chd[p][c]) {memset (chd[sz],0,sizeof (Chd[sz]));                val[sz]=0;            chd[p][c]=sz++; } P=chd[p][c];        } val[p]=k;        } void Ac_build () {int *s=q,*e=q;                for (int i=0;i<childnum;i++) {if (Chd[0][i]) {fail[chd[0][i]]=0;            *e++=chd[0][i];          }} while (s!=e) {int u=*s++;            if (Val[fail[u]]) val[u]|=val[fail[u]];                for (int i=0;i<childnum;i++) {int &v=chd[u][i];                    if (v) {*e++=v;                    Fail[v]=chd[fail[u]][i];                Val[v]= (Val[v]|val[fail[v]);            } else v=chd[fail[u]][i];        }}} int word (int n,int m) {memset (dp,0,sizeof (DP));        Dp[0][0][0][0]=1;        int CR;        int t;                 for (int i=0;i<=n;i++) {for (int. j=0;j<=m;j++) {for (int k=0;k<sz;k++)          {for (int z=0;z<4;z++)          {if (dp[i][j][k][z]==0) continue;                    Dp[i][j][k][z]%=mod;                        cout<<i<< "<<j<<" "<<k<<" "<<z<<endl;                        CR=CHD[K][0];                        T=Z|VAL[CR];                        DP[I+1][J][CR][T]+=DP[I][J][K][Z];                        Dp[i+1][j][cr][t]%=mod;                        CR=CHD[K][1];                        T=Z|VAL[CR];                        DP[I][J+1][CR][T]+=DP[I][J][K][Z];                    Dp[i][j+1][cr][t]%=mod;        }}}} int ans=0;            for (int i=0;i<sz;i++) {ans+=dp[n][m][i][3];        Ans%=mod;        } Ans=ans%mod;    cout<<ans<<endl;    }}ac;char Temp[155];int Main () {ac.init ();    int n,m,k;    int T;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &n,&m);        Ac.reset (); For (inT i=1;i<=2;i++) {scanf ("%s", temp);        Ac.insert (Temp, (1<< (i-1)));        } ac.ac_build ();    Ac.word (N,M); } return 0;}

3,hdu-4057- Rescue the Rabbit

Dp[i][j][k], representing a string of length I, located on the Trie state J, the State of the pattern string is the maximum value of K.

State compression, it becomes a normal tree DP, but also need to scroll the array to compress space.

#include <stdio.h> #include <algorithm> #include <iostream> #include <stdlib.h> #include < string.h>using namespace Std;const int maxnode=101*10;const int childnum=4;const int Mod=20090717;const int INF=    99999999;struct ac_tree{int Chd[maxnode][childnum];    int Val[maxnode];    int Fail[maxnode];    int key[1<<11];    int Q[maxnode];    int id[128];    int sz;    int dp[2][maxnode][1<<10];        void Init () {fail[0]=0;        for (int i=0;i<childnum;i++) {id[i+ ' a ']=i;        } id[' A ']=0;id[' T ']=1;    id[' G ']=2;id[' C ']=3;        } void Reset () {memset (chd,0,sizeof (CHD));    Sz=1;        } void Insert (char str[],int k,int d) {key[k]=d;        int p=0;        int Len=strlen (str);            for (int i=0;i<len;i++) {int c=id[str[i]];                if (!chd[p][c]) {memset (chd[sz],0,sizeof (Chd[sz]));                val[sz]=0; chd[p][c]=sz++;        } P=chd[p][c];    } val[p]=k;        } void Ac_build () {int *s=q,*e=q;                for (int i=0;i<childnum;i++) {if (Chd[0][i]) {fail[chd[0][i]]=0;            *e++=chd[0][i];          }} while (s!=e) {int u=*s++;            if (Val[fail[u]]) val[u]|=val[fail[u]];                for (int i=0;i<childnum;i++) {int &v=chd[u][i];                    if (v) {*e++=v;                    Fail[v]=chd[fail[u]][i];                Val[v]= (Val[v]|val[fail[v]);            } else v=chd[fail[u]][i];        }}} int word (int n,int m) {int s=0;        int l=1;        int tai= (1&LT;&LT;M);        int cr,tr;        Memset (Dp,0,sizeof (DP));        Dp[0][0][0]=1;            for (int i=0;i<n;i++) {l=1-s;           memset (dp[l],0,sizeof (dp[l)); //cout<< "__" <<endl; for (int j=0;j<sz;j++) {for (int k=0;k<tai;k++) {if (dp[s                    ][j][k]==0) continue;                    cout<<j<< "" <<k<<endl;                      for (int z=0;z<childnum;z++) {cr=chd[j][z];                        cout<<j<< "+" <<z<< "=" <<cr<<endl;                        Tr=val[cr]|k;                    Dp[l][cr][tr]=1;        }}} s=l;        } int maxx=-1;        int tt=0; for (int j=0;j<sz;j++) {for (int k=0;k<tai;k++) {if (dp[s][j][k]==0) Conti               Nue                cout<<j<< "" <<k<<endl;                tt=0;                for (int i=0;i<m;i++) {if (k& (1<<i)) tt+=key[1<<i];    }            Maxx=max (Tt,maxx); }} if (maxx<0) cout<< "No Rabbit after 2012!"        <<endl;    else cout<<maxx<<endl;    }}ac;char Temp[155];int Main () {ac.init ();    int n,m,k;        while (~SCANF ("%d%d", &n,&m)) {ac.reset ();            for (int i=1;i<=n;i++) {scanf ("%s%d", temp,&k);        Ac.insert (Temp, (1<< (I-1)), k);        } ac.ac_build ();    Ac.word (M,n); } return 0;}









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.