这道题的官方题解是dp,但是可以暴力出来。改天再研究怎么dp。

暴力的时候,如果计算sum的时候,调用strlen函数会超时,可见这个函数并不是十分的好。以后能不用尽量不用。

La Vie en rose

Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 861    Accepted Submission(s): 461

Problem Description
Professor Zhang would like to solve the multiple pattern matching problem, but he only has only one pattern string p=p1p2...pm. So, he wants to generate as many as possible pattern strings from p using the following method:

1. select some indices i1,i2,...,ik such that 1≤i1<i2<...<ik<|p| and |ij−ij+1|>1 for all 1≤j<k.
2. swap pij and pij+1 for all 1≤j≤k.

Now, for a given a string s=s1s2...sn, Professor Zhang wants to find all occurrences of all the generated patterns in s.

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains two integers n and m (1≤n≤105,1≤m≤min{5000,n}) -- the length of s and p.

The second line contains the string s and the third line contains the string p. Both the strings consist of only lowercase English letters.

Output
For each test case, output a binary string of length n. The i-th character is "1" if and only if the substring sisi+1...si+m−1 is one of the generated patterns.
Sample Input
3 4 1 abac a 4 2 aaaa aa 9 3 abcbacacb abc
Sample Output
1010 1110 100100100
Author
zimpha
Source
2016 Multi-University Training Contest 2

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
const int maxx=100005;
int main(){int t;scanf("%d",&t);while(t--){int n,m;char s[maxx];char p[maxx];scanf("%d%d",&n,&m);scanf("%s",s);scanf("%s",p);int sump[maxx];int sums[maxx];sump[0]=sums[0]=0;for(int i=1;i<=n;i++){sums[i]=s[i-1]-'a'+sums[i-1];}for(int i=1;i<=m;i++){sump[i]=p[i-1]-'a'+sump[i-1];}int pis=sump[m];int shave=sums[m];for(int i=m;i<=n;i++){shave=sums[i]-sums[i-m];// cout<<"shave: "<<shave<<endl;if(pis==shave){int sta=i-m;int pos=sta;int flag=1;for(int j=0;pos<i;j++){if(s[pos]==p[j]){pos++;}else{if(pos+1<i&&s[pos+1]==p[j]&&s[pos]==p[j+1]){pos+=2;j++;}else{flag=0;break;}}}if(flag){printf("1");}else{printf("0");}}else{printf("0");}}for(int i=m-1;i>0;i--){printf("0");}printf("\n");}return 0;
}

View Code

转载于:https://www.cnblogs.com/superxuezhazha/p/5697505.html

hdu 5745 la vie en rose相关推荐

  1. La vie en rose玫瑰人生

    Edith Piaf:La Vie En Rose 玫瑰色的人生 Des yeux qui font baiser les miens 他的双唇吻我的眼 Un rire qui se perd sur ...

  2. 这就是生活C'est La Vie

    法语好像叫C'est La Vie 记的有本书叫"为什么爱情总是与我擦肩而过" 想到一个故事,有人给一个女孩写了500封情书,结果这个女孩爱上了邮递员. 生活就是这样无奈,Ross ...

  3. hdu 4438 la 6389

    题目概述 A,B两人比赛打猎,老虎(tiger)X分,狼(wolf)Y分,两种猎物都只有一只,开始前两人会先选定各自的目标,若两人选的不同,则各打各的,都能得到自己选的猎物的分数,若选的相同,则A有P ...

  4. 2008 Cest la vie

    今年失去了一些 放弃了一些 付出了一些 改变了一些 得到了很多 有点不公平 以下是TOP 10  按时间排序 换了手机 结束了1000天 be with STT 在固废中心实习一个月 考出了ISEP软 ...

  5. 2016多校赛2 A 数学推公式 E 极角排序,组合数(待补) L dp+bitset优化

    2016 Multi-University Training Contest 2 A - Acperience 题意:给出w[],求S((w[i]-aB[i])^2)的最小值(B[i]为1或-1). ...

  6. 中物体的显示模式_美学,色彩模式,图像格式

    "神奇的一瞬间,阳光穿过透明天花板照进了毕加索的这幅画里,正好和画作完美结合在一起.坐在奥赛门口的台阶上喝咖啡,晒太阳,欣赏街头艺人表演.感谢这个随着音乐舞蹈的法国老太太,她让我明白什么是真 ...

  7. 机器人瓦力 配乐_《WALL-E》机器人小王子

    前几天看了迪斯尼的动画片<WALL-E>,很感人,并且发现了一个机器人版的小王子. 清垃圾的机器人Wall-E孤单的在废墟地球默默的日复一日辛勤工作,像个上班族每天准时上下班,干活的时候还 ...

  8. 机器人总动员最后的bgm_引导你欣赏《机器人瓦力》的电影配乐

    音乐为配合影片中出现的画面, 营造出一种特定的氛围基调.视觉上的效果带给我们的是一种直观的感受, 而伴随音乐细致入微的描写, 才能让画面更加的生动, 形象更深入人心.在动画片中, 最先出现的Put O ...

  9. 2016区域赛前冲刺训练

    UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...

  10. 机器人总动员片尾曲歌词_机器人总动员中的所有歌曲叫什么名?

    展开全部 <机器人总动员>的原声皆由托马斯·纽曼主导创作. 歌曲包e68a843231313335323631343130323136353331333431343730括: 1.Put ...

最新文章

  1. strtotime 获取当月最后一天的日期
  2. java mysql乐观锁_java乐观锁使用
  3. 【Java】Calendar获取年、月、日、时间
  4. 编程之美 --1 : 骨牌覆盖问题·一
  5. java里 currenttime_java 获取当前时间LocalDateTime currentTimeMillis java.util.Date
  6. Python基础教程(二):基础语法、变量类型
  7. 【产品】腾讯内部的顶级产品课:灵动在细节
  8. Linux学习:目录操作函数
  9. R语言中的特殊值 NA NULL NaN Inf
  10. python random.randint未定义_学习python - 无法弄清楚random.randint
  11. 05-windows下R安装包的几种方式
  12. php删除提示信息,php删除一条记录(删除确认提示)
  13. QT 按钮(4种样式)
  14. 安卓android中国象棋chess程序项目源码源代码,C/C++编程笔记:C语言打造中国象棋游戏,项目源代码分享!,c语言笔记大全...
  15. spring学习--bean--普通bean与工厂bean(FactoryBean)区别
  16. php常用的几个算法
  17. 23.方法重写的本质与虚方法表的使用
  18. 114-select(基础)
  19. 2019年任正非给全体华为员工的信
  20. 基于51单片机GSM模块的家庭防火防盗报警系统

热门文章

  1. 计算机的存储容量1kb表示什么,计算机的存储容量常用KB为单位,这里1KB表示什么?...
  2. ubuntu搜狗拼音输入法无法切换英文
  3. 【SCOI2009】粉刷匠
  4. 简单银行账户管理系统
  5. 使用BPEL创建Web服务组合
  6. R语言 面板数据分析 plm包实现(三)——面板数据与面板模型的检验
  7. oracle 数据库模式对象,索引,序列,同义词,查看用户拥有的表,聚簇,数据库链接
  8. python的标准随机数生成器模块_Python:带均值和标准差的随机数生成器
  9. 人性化的绘画界面设计-屁民科普
  10. root 账号不能登录的解决方法