zoukankan      html  css  js  c++  java
  • 大白书 209 remember the word

    F - Remember the Word
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Appoint description: 

    Description

    Download as PDF
     

    Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie.

    Since Jiejie can't remember numbers clearly, he just uses sticks to help himself. Allowing for Jiejie's only 20071027 sticks, he can only record the remainders of the numbers divided by total amount of sticks.

    The problem is as follows: a word needs to be divided into small pieces in such a way that each piece is from some given set of words. Given a word and the set of words, Jiejie should calculate the number of ways the given word can be divided, using the words in the set.

    Input 

    The input file contains multiple test cases. For each test case: the first line contains the given word whose length is no more than 300 000.

    The second line contains an integer S<tex2html_verbatim_mark> , 1$ le$S$ le$4000<tex2html_verbatim_mark> .

    Each of the following S<tex2html_verbatim_mark> lines contains one word from the set. Each word will be at most 100 characters long. There will be no two identical words and all letters in the words will be lowercase.

    There is a blank line between consecutive test cases.

    You should proceed to the end of file.

    Output 

    For each test case, output the number, as described above, from the task description modulo 20071027.

    Sample Input 

    abcd 
    4 
    a 
    b 
    cd 
    ab
    

    Sample Output 

    Case 1: 2
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int ch[500010][32],val[500010];
    int sz,d[500010];
    int idx(char c)
    {
        return c-'a';
    }
    void insert(char *s,int v)
    {
        int  u=0,n=strlen(s);
        for(int i=0;i<n;i++)
        {
            int c=idx(s[i]);
            if(!ch[u][c])
            {
                memset(ch[sz],0,sizeof(ch[sz]));
                val[sz]=0;
                ch[u][c]=sz++;
            }
            u=ch[u][c];
        }
        val[u]=v;
    }
    int main()
    {
        char s[500010],a[105];
         int  i,x,t=1,j;
        while(~scanf("%s",s))
         {
             memset(d,0,sizeof(d));
              sz=1;
            memset(ch[0],0,sizeof(ch[0]));
             scanf("%d",&x);
             for(i=1;i<=x;i++)
             {
                 scanf("%s",a);
                 insert(a,-1);
             }
             int root,i,j,k;
             int len=strlen(s);
              d[len]=1;
           for(i=len-1;i>=0;i--)
            {
                 root=0;
              for(j=0,k=i;k<len;j++,k++)
               {
                 int c=idx(s[k]);
                 if(ch[root][c]==0)
                    break;
                 else if(val[ch[root][c]]==-1)
                 {
                   d[i] += d[i+j+1];
                  if(d[i] >= 20071027) d[i] %= 20071027;
                 }
                  root=ch[root][c];
              }
    
         }
             printf("Case %d: %d
    ",t++,d[0]%20071027);
         }
    }
  • 相关阅读:
    PAIP.paip.手机离线ROOT过程总结
    paip.程序设计扫号器跑号器结果分类设计
    PAIP.测试硬盘的成色以及速率
    paip.httpd.conf 是空的.txt
    paip.c#.nett 系统托盘动态图标闪烁图标
    paip.验证码识别反馈法提高识别率
    paip.提升用户体验找回密码的设
    paip.sql2008 客户端软件绿色版V319
    提升用户体验自动邮编提示与验证地址
    PAIP.提升性能---LISTBOX加载30万大数据量终结方案
  • 原文地址:https://www.cnblogs.com/cancangood/p/4333477.html
Copyright © 2011-2022 走看看