一道水题?
来源:互联网 发布:mysql禁用反向解析 编辑:程序博客网 时间:2024/06/10 22:10
Description
Let's introduce the designation , wherex is a string, n is a positive integer and operation " + " is the string concatenation operation. For example,[abc, 2] = abcabc.
We'll say that string scan be obtained from stringt, if we can remove some characters from stringt and obtain string s. For example, strings ab andaсba can be obtained from string xacbac, and strings bx andaaa cannot be obtained from it.
Sereja has two strings, w = [a, b] andq = [c, d]. He wants to find such maximum integerp(p > 0), that[q, p] can be obtained from stringw.
Input
The first line contains two integers b,d(1 ≤ b, d ≤ 107). The second line contains stringa. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed100.
Output
In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.
Sample Input
10 3ababbab
3
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;typedef long long ll;char a[1005],b[1005]; //两个串int cnt[1005]; //重要的数组,异常重要int n,m,la,lb,ans;int main(){ while(scanf("%d%d",&n,&m)!=EOF) { cin>>a>>b; memset(cnt,0,sizeof(cnt)); ans=0; int la=strlen(a); int lb=strlen(b); for(int i=0;i<lb;i++) { for(int j=0;j<la;j++) { if(b[(i+cnt[i])%lb]==a[j]) cnt[i]++; //重点,cnt[i]表示从b串中第i个点开始能在a串中找到的最大的连续可重复b串 } } for(int i=0;i<n;i++) ans=ans+cnt[ans%lb]; //重点,ans%lb的意义使每次重新加时都是从第i个字母开始从而保持了b串的连续性 printf("%d\n",ans/lb/m); }}
- nyoj525 一道水题
- POJ3753-一道水题
- 一道水题Q2013
- 一道水题Q2031
- 一道水题Q2000
- 一道水题Q2001
- 一道水题Q2004
- NYOJ525 一道水题
- 一道水题
- poj1004 水题一道
- nyoj 一道水题
- 南阳 一道水题
- 一道水题
- NOIP一道水题
- nyoj525 一道水题
- 一道水题
- 一道水题
- hdu1257一道水题??
- linux下screen命令使用记录
- java代码操作redis:
- ACM初窥门径(一)
- js统计字符串中字符出现的个数以及最大个数
- caffe:create_txt.sh(数据预处理成txt文本文件)
- 一道水题?
- Python文件执行代码步骤
- NDK编译——ndk-build
- 微信小程序Radio选中样式切换
- Java多线程系列--“基础篇”09之 interrupt()和线程终止方式
- 百度Apollo简介
- ubuntu 17.04 安装vmware tools
- 文件和流学习总结1
- Repository和Registry区别