CF_314D_Sereja and Periods
2013-06-08 22:04
344 查看
情况分为两种
第一种情况:c中有a中没有的字符,那么输出0.
第二种:a重复strlen(c)次,得到ac字符串,从ac中找最短的重复次数(strlen(c)是上限,因为至少每个串抽一个字符出来才能满足有串)。
第一种情况:c中有a中没有的字符,那么输出0.
第二种:a重复strlen(c)次,得到ac字符串,从ac中找最短的重复次数(strlen(c)是上限,因为至少每个串抽一个字符出来才能满足有串)。
#include<iostream> #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #include <cmath> #include<vector> #include<string> using namespace std; #define LL long long int divide[105],mod[105]; int main() { int b,d; scanf("%d%d",&b,&d); string a,c; cin>>a>>c; int now; for(int i=0;i<c.length();++i) { now=i; for(int j=0;j<a.length();++j) { if(c[now%c.length()]==a[j]) now++; } divide[i]=now/c.length(); //divide[i]表示从c的第i个字符开始在a串中最多有多少个c串 mod[i]=now%c.length(); //mod[i]表示从c的第i个字符开始在a串中最末尾的字符+1 } LL res=0; now=0; for(int i=0;i<b;++i) { res+=divide[now]; now=mod[now]; } cout<<res/d<<endl; return 0; }
相关文章推荐
- CodeForces 314 B.Sereja and Periods 思维+简单dp【转】
- CodeForces 314B - Sereja and Periods 很有思维的DP
- CF 314B: Sereja and Periods
- CF_315B_Sereja and Array
- CF_315C_Sereja and Contest
- CF 314 E. Sereja and Squares
- CF - 314C - Sereja and Subsequences(树状数组+dp)
- cf Sereja and Array
- CF 314A(Sereja and Contest-这题题目索性没看懂,E文是硬伤)
- CF 315B - Sereja and Array(树状数组)
- CF-Sereja and Algorithm
- CF 380C - Sereja and Brackets(线段树)
- CodeForces 314 B.Sereja and Periods(dp)
- cf B. Jeff and Periods
- B. Sereja and Suffixes(cf)
- CF380A Sereja and Prefixes
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
- Codeforces #187 (Div. 1) B. Sereja and Periods && Hihocoder 1355 (字符串匹配倍增好题)
- cf B. Sereja and Suffixes
- cf-381A-Sereja and Dima