BZOJ1030: [JSOI2007] Text generator

Source: Internet
Author: User

"Portal: BZOJ1030" Brief test Instructions:

Give n words, ask for the number of strings with at least one word in length n

The following:

Obviously it's hard to find out, so we'll find out the total number of strings, and then find the number of strings that don't contain any one word.

Then subtract is the answer.

It's like a GT exam, but it turns into a bunch of strings, so use AC automata

Set F[I][J] is the number of strings without any one word to the first J point of the dictionary tree when the length is I

Just make sure the state is reasonable and you can inherit the

Reference Code:
#include <cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using namespacestd;intMod=10007;structtrie{intc[ -],s,fail;} t[11000];intTot,root;voidCleanintx) {memset (t[x].c,-1,sizeof(T[X].C)); T[x].s=0;}Charst[ the];voidbt () {intx=0, Len=strlen (st+1);  for(intI=1; i<=len;i++)    {        inty=st[i]-'A'+1; if(t[x].c[y]==-1) Clean (++tot), t[x].c[y]=tot; X=T[x].c[y]; } T[X].S=1;}intlist[11000];voidBFs () {list[1]=0; intHead=1, tail=1;  while(head<=tail) {        intx=List[head];  for(intI=1; i<= -; i++)        {            intson=T[x].c[i]; if(son==-1)Continue; if(x==0) t[son].fail=0; Else            {                intj=T[x].fail;  while(j!=0&&t[j].c[i]==-1) j=T[j].fail; T[son].fail=max (0, T[j].c[i]); if(t[t[son].fail].s==1) t[son].s=1; } list[++tail]=Son; } head++; }}intf[ the][11000];intMain () {intn,m; scanf ("%d%d",&n,&m); Tot=0; Clean (0);  for(intI=1; i<=n;i++) {scanf ("%s", st+1);    BT ();    } BFS (); Memset (F,0,sizeof(f)); intsum=1;  for(intI=1; i<=m;i++) sum= (sum* -)%Mod; f[0][0]=1;  for(intu=1; u<=m;u++)    {         for(intI=0; i<=tot;i++)        {            if(t[i].s==0&&f[u-1][i]>0)            {                 for(intj=1; j<= -; j + +)                {                    intk=i;  while(k!=0&&t[k].c[j]==-1) k=T[k].fail; intson=T[k].c[j]; if(son==-1) son=0; F[u][son]= (f[u][son]+f[u-1][i])%Mod; }            }        }    }    intans=0;  for(intI=0; i<=tot;i++)if(t[i].s==0) ans= (Ans+f[m][i])%Mod; printf ("%d\n", ((Sum-ans)%mod+mod)%Mod); return 0;}

BZOJ1030: [JSOI2007] Text generator

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.