2016暑假多校联合---Another Meaning
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.
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|
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”.
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- const long long mod=1e9+;
- char s[];
- char ss[];
- int next1[];
- long long num[];
- int pos[];
- void makenext1(const char P[])
- {
- int q,k;
- int m = strlen(P);
- next1[]=;
- for (q = ,k = ; q < m; ++q)
- {
- while(k > && P[q] != P[k])
- k = next1[k-];
- if (P[q] == P[k])
- {
- k++;
- }
- next1[q] = k;
- }
- }
- long long calc(char T[],char P[])
- {
- int n,m;
- int i,q;
- int tot=;
- n = strlen(T);
- m = strlen(P);
- makenext1(P);
- for(i=,q = ; i < n; ++i)
- {
- while(q>&&P[q]!=T[i])
- q=next1[q-];
- if(P[q]==T[i])
- {
- q++;
- }
- if(q==m)
- {
- long long flag=;
- pos[tot]=i-m+;
- if(tot>)
- {
- if(pos[tot-]+m<=pos[tot])
- {
- num[tot]=(*num[tot-])%mod;
- }
- else
- {
- num[tot]=num[tot-]%mod;
- for(int h=tot-;h>=;h--)
- {
- if(pos[h]+m<=pos[tot])
- {
- num[tot]=(num[tot]+num[h])%mod;
- flag=; ///当之前不存在不相重叠的语句时;
- break;
- }
- }
- num[tot]=(num[tot]+flag)%mod;
- }
- }
- else
- {
- num[tot]=;
- }
- tot++;
- }
- }
- if(tot==) return ;
- return num[tot-];
- }
- int main()
- {
- int T;
- int Case=;
- cin>>T;
- while(T--)
- {
- scanf("%s%s",s,ss);
- printf("Case #%d: %lld\n",Case++,calc(s,ss));
- // cout<<(calc(s,ss)%mod+mod)%mod<<endl;
- }
- return ;
- }
2016暑假多校联合---Another Meaning的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- 2016暑假多校联合---Counting Intersections
原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...
- 2016暑假多校联合---Joint Stacks (STL)
HDU 5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...
- 2016暑假多校联合---GCD
Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...
随机推荐
- Atitit 发帖机实现(4 )- usbQBM1601 gui操作标准化规范与解决方案attilax总结
Atitit 发帖机实现(4 )- usbQBM1601 gui操作标准化规范与解决方案attilax总结 1.1. 根据gui的类型使用不同的gui调用api1 1.2. Script化1 1.3. ...
- binary 和 varbinary 用法
数据类型 binary(n) 和 varbinary(n) 用于存储二进制数据,n是指字节数量: binary( n ):长度为 n 字节的固定长度二进制数据,其中 n 是从 1 到 8,000 的值 ...
- ::after::before清除浮动原理
先来看一段代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- 使用AssetsLibrary.Framework创建多图片选择控制器(翻译)
系统的UIImagePickerController只能让用户选择单图片,而一般情况下,我们需要上传多张图片,这时应该可以同时选择多张图片,否则用户体验会很差.因此多图片选择器就诞生了. 在类库中,苹 ...
- WPF自定义控件与样式(14)-轻量MVVM模式实践
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. MVVM是WPF中一个非 ...
- Android入门(六)碎片
原文链接:http://www.orlion.ga/493/ 一.碎片 碎片(Fragment)是一种可以嵌入在活动当中的 UI片段,它能让程序更加合理和充分地利用大屏幕的空间,因而在平板上应用的非常 ...
- PHP 对象 “==” 与 “===”
php中对象在内存中的存储方式与java等其他面向对象语言类似,$a = new Person();在内存中表现为$a是堆区中new Person()中的引用 这样当: $a = new Person ...
- elasticsearch中的API
elasticsearch中的API es中的API按照大类分为下面几种: 文档API: 提供对文档的增删改查操作 搜索API: 提供对文档进行某个字段的查询 索引API: 提供对索引进行操作 查看A ...
- 关于IHttpModule的相关知识总结
一.IHttpModule相关概述 using System; namespace System.Web { public interface IHttpModule { // 销毁不再被HttpMo ...
- 【Swift学习】Swift编程之旅---继承(十七)
在 Swift 中,继承是区分「类」与其它类型的一个基本特征.swift不支持多重继承.类可以调用和访问超类的方法,属性和subscripts下标,并且可以重写(override)这些方法,属性和附属 ...