HDU 5763 Another meaning

Source: Internet
Author: User

Title: Another meaning

Links:http://acm.hdu.edu.cn/showproblem.php?pid=5763

Test Instructions: each time you give two strings s, T, string T has two meanings, ask S string has several meanings. For example s= "AB", t= "a", A has two meanings, assuming that: original A, different meaning *, then AB has two meanings: AB, *b.

Ideas:

s string is saved from 1

Use Dp[i] to denote s[1...i] has several meanings. If the end of S is not equal to t (or not as T, meaning constant), then dp[i]=dp[i-1], if S end as T (meaning change), then Dp[i]=dp[i-len].

Make dp[0]=1; Length of Len=t

If the end of I equals T, then Dp[i]=dp[i-1]+dp[i-len]. If not, dp[i]=dp[i-1]. Pay attention to the modulo.

There is a hole in the game, the code has next has been CE, but now is not.

AC Code:

1#include <stdio.h>2#include <string.h>3 intnext[10010];//Next Array4 Chars[10010];//Pattern String5 Charst[1000010];//Original String6 voidGet_next ()7 {8next[0]=-1;9next[1]=0;Ten   //if there's nothing in S, be careful to add a special sentence. One   intI=1, j=0; A    while(S[i]) -   { -     if(S[i]==s[j]) next[++i]=++J; the     Else if(next[j]!=-1) j=Next[j]; -     Elsei++; -   } - } +  -  +  A Long Longdp[100010]; at intMain () - { -   intt,cas=1; -scanf"%d",&t); -    while(t--) -   { inscanf"%s", st+1); -scanf"%s", s); to Get_next (); +     intlen=strlen (s); -     inti,j=0; thedp[0]=1; *      for(i=1; St[i];) $     {Panax Notoginseng       if(st[i]==S[j]) -       { theJ + +; +         if(s[j]==0) A         { theDp[i]= (dp[i-1]+dp[i-len])%1000000007; +         } -         Elsedp[i]=dp[i-1]; $i++; $       } -       Else if(next[j]!=-1) j=Next[j]; -       Else the       { -dp[i]=dp[i-1];Wuyii++; the       } -     } Wuprintf"Case #%d:%i64d\n", cas++,dp[i-1]); -   } About   return 0; $}

HDU 5763 Another meaning

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.