http://codeforces.com/contest/536/problem/B
2 seconds
256 megabytes
standard input
standard output
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.

Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≤ i ≤ k) he condition sxisxi + 1... sxi + |p| - 1 = pis fullfilled.
Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all).
After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.
Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.
Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7.
The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 106 and0 ≤ m ≤ n - |p| + 1).
The second line contains string p (1 ≤ |p| ≤ n).
The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≤ y1 < y2 < ... < ym ≤ n - |p| + 1).
In a single line print the answer modulo 1000 000 007.
6 2
ioi
1 3
26
5 2
ioi
1 2
0
In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.
Here |x| denotes the length of string x.
Please note that it's possible that there is no such string (answer is 0).
题意:给一长度为n的字符串,和字符子串b,以及子串出现的位置,问你原字符串有多少种可能性?
题解:第一个KMP,先用一个vis的数组标记子串第个字符出现的位置,用kmp,去验证子串是否出现了M次,少于的话就是0;验证的过程中再用以个vis1数组标记子串
出现过的位置(两个vis这样可以免去赋值很巧妙有没有,我学别人的http://www.cnblogs.com/widsom/p/7364861.html)最后求出没有被标记的个数ans,26^ans%mod就是答案。代码如下:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;
const int maxn=1e6+;
const int mod=1e9+;
bool vis[maxn],vis1[maxn];
int b,f[maxn],n,m;
//char a[maxn];
string a;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cin>>n>>m;
cin>>a;
for(int i=;i<m;i++)
{
cin>>b;
vis[b-]=true;
}
//int len=strlen(a);
int len=a.size();
f[]=-;
// memset(f,-1,sizeof(f));
for(int i=;i<len;i++)
{
int j=f[i-];
while((a[i]!=a[j+])&&j>=)
{
j=f[j];
}
if(a[j+]==a[i])
f[i]=j+;
else
f[i]=-;
}
int i=,j=;
int tmp=;
int t=-;
while(i<n)
{
if(vis[i])t=i;
if(t!=-)
{
if(i-t<len)
{
vis1[i]=true;
if(a[i-t]==a[j])
{
j++;
i++;
if(j==len)
{
tmp++;
j=f[j-]+;
}
}
else
{
if(j==)
{
i++;
}
else
j=f[j-]+;
}
}
else
i++; }
else
{
i++;
} }
if(tmp<m)
{
cout<<<<endl;
}
else
{
tmp=;
ll ans=;
for(i=;i<n;i++)
{
if(!vis1[i])ans=(ans*)%mod;
}
cout<<ans<<endl;
}
return ;
}
学习kmp这篇博客不错博主用心了http://www.cnblogs.com/SYCstudio/p/7194315.html
http://codeforces.com/contest/536/problem/B的更多相关文章
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
- http://codeforces.com/contest/555/problem/B
比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...
- http://codeforces.com/contest/610/problem/D
D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- http://codeforces.com/contest/535/problem/C
C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- http://codeforces.com/contest/838/problem/A
A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- http://codeforces.com/contest/402/problem/E
E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces.com/contest/251/problem/C
C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- jmeter-fileupload操作使用说明
前言:在http请求过程中上传附件(图片.安装包.视频文件等)虽然基本上Content-Type为:multipart/form-data,但Content-Type也有不一样的,如:图片Conten ...
- 安装JDK详细步骤,以及环境变量配置
1.JDK 1)下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 点击同意, ...
- 没有闲话和grunt.initConfig()
grunt.initConfig()为Gruntfile.js的核心部分,它接收对象作为参数. 对象包含两种类型的属性,一种是单纯的变量,一种是task类型.举个栗子: grunt.initConfi ...
- 字符编码笔记:ASCII,Unicode和UT…
字符编码笔记:ASCII,Unicode和UTF-8 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才 ...
- [转载]历上最强的音乐播放器(jetAudio-8.0.5.320-Plus-VX
原文地址:历上最强的音乐播放器(jetAudio-8.0.5.320-Plus-VX-完全汉化版)下载作者:盖世天星 历上最强的音乐播放器(jetAudio-8.0.5.320-Plus-VX-完全汉 ...
- IT经典书籍——Head First系列【推荐】
Head First 系列书籍是由 O'Relly 出版社发行的一系列教育书籍,中文一般翻译为"深入浅出",它强调以特殊的方式排版,由大量的图片和有趣的内容组合构成,而达到非疲劳的 ...
- 【DDD】领域驱动设计实践 —— 业务建模实例(‘发布帖子’)
本文是基于上一篇‘业务建模小招数’的实践,后面的多篇博文类似.本文主要讲解‘发表帖子’场景的业务建模,包括:业务建模.业务模型.示例代码:示例代码会使用java编写,文末附有github地址.相比于& ...
- 学号:201521123116 《java程序设计》第六周学习总结
1. 本章学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2.书面作业 1.1.Object对象中的clone方法是 ...
- 201521123062《Java程序设计》第10周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中fin ...
- JAVA课程设计-----加减法测试博客
1.团队成员介绍(一个人做的) 谢季努:网络1513 201521123079 2.项目git地址 3.项目git提交截图 4.项目运行截图 输入答案后点击确认就会出现本次的得分 如果觉得成绩不理想点 ...