Problem Description
As is known to all, in many cases, a word has two meanings. Such as “hehe”, which not only means “hehe”, but also means “excuse me”. 
Today, ?? is chating with MeiZi online, MeiZi sends a sentence A to ??. ?? is so smart that he knows the word B in the sentence has two meanings. He wants to know how many kinds of meanings MeiZi can express.
 
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each test case contains two strings A and B, A means the sentence MeiZi sends to ??, B means the word B which has two menaings. string only contains lowercase letters.

Limits
T <= 30
|A| <= 100000
|B| <= |A|

 
Output
For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the number of the different meaning of this sentence may be. Since this number may be quite large, you should output the answer modulo 1000000007.
 
Sample Input
4
hehehe
hehe
woquxizaolehehe
woquxizaole
hehehehe
hehe
owoadiuhzgneninougur
iehiehieh
 
Sample Output
Case #1: 3
Case #2: 2
Case #3: 5
Case #4: 1

Hint

In the first case, “ hehehe” can have 3 meaings: “*he”, “he*”, “hehehe”.
In the third case, “hehehehe” can have 5 meaings: “*hehe”, “he*he”, “hehe*”, “**”, “hehehehe”.

 
思路:递推(DP) 当前位置以前的语句的含义种数为包含当前多语义与不包含;
 
代码如下:
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. using namespace std;
  6. const long long mod=1e9+;
  7.  
  8. char s[];
  9. char ss[];
  10. int next1[];
  11. long long num[];
  12. int pos[];
  13.  
  14. void makenext1(const char P[])
  15. {
  16. int q,k;
  17. int m = strlen(P);
  18. next1[]=;
  19. for (q = ,k = ; q < m; ++q)
  20. {
  21. while(k > && P[q] != P[k])
  22. k = next1[k-];
  23. if (P[q] == P[k])
  24. {
  25. k++;
  26. }
  27. next1[q] = k;
  28. }
  29. }
  30.  
  31. long long calc(char T[],char P[])
  32. {
  33. int n,m;
  34. int i,q;
  35. int tot=;
  36. n = strlen(T);
  37. m = strlen(P);
  38. makenext1(P);
  39. for(i=,q = ; i < n; ++i)
  40. {
  41. while(q>&&P[q]!=T[i])
  42. q=next1[q-];
  43. if(P[q]==T[i])
  44. {
  45. q++;
  46. }
  47. if(q==m)
  48. {
  49. long long flag=;
  50. pos[tot]=i-m+;
  51. if(tot>)
  52. {
  53. if(pos[tot-]+m<=pos[tot])
  54. {
  55. num[tot]=(*num[tot-])%mod;
  56. }
  57. else
  58. {
  59. num[tot]=num[tot-]%mod;
  60. for(int h=tot-;h>=;h--)
  61. {
  62. if(pos[h]+m<=pos[tot])
  63. {
  64. num[tot]=(num[tot]+num[h])%mod;
  65. flag=; ///当之前不存在不相重叠的语句时;
  66. break;
  67. }
  68. }
  69. num[tot]=(num[tot]+flag)%mod;
  70. }
  71. }
  72. else
  73. {
  74. num[tot]=;
  75. }
  76. tot++;
  77. }
  78. }
  79. if(tot==) return ;
  80. return num[tot-];
  81. }
  82.  
  83. int main()
  84. {
  85. int T;
  86. int Case=;
  87. cin>>T;
  88. while(T--)
  89. {
  90. scanf("%s%s",s,ss);
  91. printf("Case #%d: %lld\n",Case++,calc(s,ss));
  92. // cout<<(calc(s,ss)%mod+mod)%mod<<endl;
  93. }
  94. return ;
  95. }

2016暑假多校联合---Another Meaning的更多相关文章

  1. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  2. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  3. 2016暑假多校联合---Substring(后缀数组)

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  4. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

  5. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

  6. 2016暑假多校联合---Death Sequence(递推、前向星)

    原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...

  7. 2016暑假多校联合---Counting Intersections

    原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...

  8. 2016暑假多校联合---Joint Stacks (STL)

    HDU  5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...

  9. 2016暑假多校联合---GCD

    Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...

随机推荐

  1. Atitit 发帖机实现(4 )- usbQBM1601 gui操作标准化规范与解决方案attilax总结

    Atitit 发帖机实现(4 )- usbQBM1601 gui操作标准化规范与解决方案attilax总结 1.1. 根据gui的类型使用不同的gui调用api1 1.2. Script化1 1.3. ...

  2. binary 和 varbinary 用法

    数据类型 binary(n) 和 varbinary(n) 用于存储二进制数据,n是指字节数量: binary( n ):长度为 n 字节的固定长度二进制数据,其中 n 是从 1 到 8,000 的值 ...

  3. ::after::before清除浮动原理

    先来看一段代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. 使用AssetsLibrary.Framework创建多图片选择控制器(翻译)

    系统的UIImagePickerController只能让用户选择单图片,而一般情况下,我们需要上传多张图片,这时应该可以同时选择多张图片,否则用户体验会很差.因此多图片选择器就诞生了. 在类库中,苹 ...

  5. WPF自定义控件与样式(14)-轻量MVVM模式实践

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. MVVM是WPF中一个非 ...

  6. Android入门(六)碎片

    原文链接:http://www.orlion.ga/493/ 一.碎片 碎片(Fragment)是一种可以嵌入在活动当中的 UI片段,它能让程序更加合理和充分地利用大屏幕的空间,因而在平板上应用的非常 ...

  7. PHP 对象 “==” 与 “===”

    php中对象在内存中的存储方式与java等其他面向对象语言类似,$a = new Person();在内存中表现为$a是堆区中new Person()中的引用 这样当: $a = new Person ...

  8. elasticsearch中的API

    elasticsearch中的API es中的API按照大类分为下面几种: 文档API: 提供对文档的增删改查操作 搜索API: 提供对文档进行某个字段的查询 索引API: 提供对索引进行操作 查看A ...

  9. 关于IHttpModule的相关知识总结

    一.IHttpModule相关概述 using System; namespace System.Web { public interface IHttpModule { // 销毁不再被HttpMo ...

  10. 【Swift学习】Swift编程之旅---继承(十七)

    在 Swift 中,继承是区分「类」与其它类型的一个基本特征.swift不支持多重继承.类可以调用和访问超类的方法,属性和subscripts下标,并且可以重写(override)这些方法,属性和附属 ...