kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。
Sample Input
- abcde a3
- aaaaaa aa
- #
Sample Output
- 0
- 3
- kmp裸题,不同的是不能重叠。
不能重叠 j=0 重叠的话是 j=Next[j]
比较好理解。因为不重叠就当前i和j=0 重叠就是当前i和Next[j],前面部分重叠(i之前的k个)
- #include<stdio.h>
- #include<string.h>
- int Next[],n,m,tlen,plen;
- char t[],p[];
- void prekmp() {
- int i,j;
- tlen=strlen(t);
- plen=strlen(p);
- j=Next[]=-;
- i=;
- while(i<plen) {
- while(j!=-&&p[i]!=p[j]) j=Next[j];
- if(p[++i]==p[++j]) Next[i]=Next[j];
- else Next[i]=j;
- }
- }
- int kmp() {
- prekmp();
- int i,j,ans=;
- i=j=;
- while(i<tlen) {
- while(j!=-&&t[i]!=p[j]) j=Next[j];
- i++;j++;
- if(j>=plen) {
- ans++;
- j=;//不重叠
- }
- }
- return ans;
- }
- int main() {
- while(~scanf("%s",t)) {
- if(t[]=='#') break;
- scanf("%s",p);
- printf("%d\n",kmp());
- }
- }
kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条的更多相关文章
- hdu2087 剪花布条
剪花布条 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- [Python]python CGI脚本在apache服务器上运行时出现“Premature end of script headers”错误
在测试自己的python CGI脚本时, 当html网页中的表单form内容传送到服务器python脚本时, 总是出现Premature end of script headers错误, 网页显示是服 ...
- JavaScript基本概念B - 关于方法
方法也是对象 这个事需要反复强调.方法是 类型 Function 的对象,和其他对象一样,它也有方法. function gen() { return function ans(factor) { r ...
- 第十四章 Spring MVC的工作机制与设计模式(待续)
Spring MVC的总体设计 Control设计 Model设计 View设计 框架设计的思考 设计模式解析之模版模式
- Centos 7.2 安装稳定版 nginx
1. 创建适用于RHEL/CentOS系统的安装源文件,位置为: /etc/yum.repos.d/nginx.repo , 并写入以下内容: [nginx] name=nginx repo base ...
- java 多线程系列---JUC原子类(三)之AtomicLongArray原子类
AtomicLongArray介绍和函数列表 在"Java多线程系列--“JUC原子类”02之 AtomicLong原子类"中介绍过,AtomicLong是作用是对长整形进行原子操 ...
- Linux-CentOS 学习的坎坷路 (一) 网络配置篇
自己学习的地址:http://www.imooc.com/view/175 学到2.8章节,配置IP这一块,妈蛋,他直接跳过了,都不知道怎么配置,无奈,只能Search 先是找到配置IP的方法: ht ...
- 【263】Linux 添加环境变量 & 全局 shell 脚本
Linux电脑添加环境变量 方法一:通过修改 profile 文件添加环境变量 1. 打开终端,输入[vi /etc/profile],如下所示,点击回车 [ocean@ygs-jhyang-w1 L ...
- madplay的使用方法
管理madplay的主程序,包括播放,暂停播放,恢复播放,停止播放 system("madplay north.mp3 &");//利用system函数调用madplay播 ...
- C++ 私有构造函数的作用
很多情况下要求当前的程序中只有一个object.例如一个程序只有一个和数据库的连接,只有一个鼠标的object.通常我们都将构造函数的声明置于public区段,假如我们将 其放入private区段中会 ...
- Codeforces 1107E (Vasya and Binary String) (记忆化,DP + DP)
题意:给你一个长度为n的01串,和一个数组a,你可以每次选择消除一段数字相同的01串,假设消除的长度为len,那么收益为a[len],问最大的收益是多少? 思路:前两天刚做了POJ 1390,和此题很 ...