KMP Tavas and Malekas:CodeForces 535D
来源:互联网 发布:淘宝买小米平板 编辑:程序博客网 时间:2024/05/19 01:29
题目CodeForces 535D
time limit per test2 seconds
memory limit per test256 megabytes
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 = p is 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.
Input
The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 10^6 and 0 ≤ 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).
Output
In a single line print the answer modulo 1000 000 007.
Examples
input
6 2
ioi
1 3
output
26
input
5 2
ioi
1 2
output
0
Note
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的字符串,告诉你他的一个子串以及这个子串出现的若干个位置。问这种长度为N的字符串有多少种可能性。
思路:
按照子串的出现位置,将字符串确定的部分确定下来,剩下没确定的位置个数若为m,则答案即是
hash/kmp
这题的基本思路就是判断重叠部分是否满足要求。(有可能位置信息冲突导致答案为0)
hash:
求出相应部分的哈希值来判断即可。
kmp:
先把字符串确定出来(重叠部分按照先后顺序来确定),用kmp来判断是否在读入的每个位置都能够匹配。
代码:待补充
- KMP Tavas and Malekas:CodeForces 535D
- KMP||扩展KMP(Codeforces 535D - Tavas and Malekas )
- Codeforces Round #299 (Div. 2)-D. Tavas and Malekas(kmp)
- codeforces 535D. Tavas and Malekas----#299div2D
- Codeforces Round #299 (Div. 2) D. Tavas and Malekas KMP+预处理、string suffix structures
- codeforces535D:Tavas and Malekas(KMP)
- codeforces535D:Tavas and Malekas(KMP)
- codeforces535D Tavas and Malekas kmp
- CF 299 div2 D. Tavas and Malekas(KMP)
- Codeforces 536B Tavas and Malekas 求自身首尾的重叠位置 KMP
- Codeforces 536B Tavas and Malekas kmp找所有与前缀匹配的后缀
- cf#299 Tavas and Malekas
- 【Codeforces Round 299 (Div 2)D】【KMP 本质是最前与最后匹配】Tavas and Malekas 长度为n的匹配串被模板串多位点覆盖的匹配串个数
- Codeforces 535C Tavas and Karafs(二分)
- Codeforces 535C Tavas and Karafs
- CodeForces 535B — Tavas and SaDDas
- [Codeforces 535B]Tavas and Karafs
- codeforces 535B-Tavas and SaDDas
- Sublime Text 插件安装
- Linux 下的ls命令
- C++11 随机数学习
- UNIX网络编程1:传输层协议TCP、UDP、SCTP
- python和anaconda
- KMP Tavas and Malekas:CodeForces 535D
- 为android编写linux内核驱动
- Apache Cassandra (三)solr 的使用
- for和foreach那个效率更高?原因是什么?
- 数据库中Schema和Database有什么区别
- obc学习笔记6
- 第三篇 流程控制
- 001_JS中slice,splice,split的区别
- Linux学习第十篇--修改文件的时间