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