【bzoj 十连测】[noip2016第一场]Problem A: String Master(暴力)
2016-11-16 19:45
513 查看
【题解】【暴力】
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[310],b[310];
int len,k,ans;
inline void solve()
{
int i,j;
for(i=1;i<=len;++i)
for(j=1;j<=len;++j)
if(a[i]==b[j]&&len-j+1>=ans&&len-i+1>=ans)
{
int t1=i,t2=j,sum=0;
while(t1<=len&&t2<=len&&a[t1]==b[t2]) t1++,t2++,sum++;
if(ans<sum) ans=sum;
}
printf("%d\n",ans);
}
int main()
{
//freopen("master.in","r",stdin);
//freopen("master.out","w",stdout);
int i,j;
scanf("%d%d",&len,&k);
scanf("%s%s",a+1,b+1);
if(len==k) {printf("%d\n",len); return 0;}
if(!k) {solve(); return 0;}
for(i=1;i<=len;++i)
for(j=1;j<=len;++j)
if(len-j+1>=ans&&len-i+1>=ans)
{
int t1=i,t2=j,sum=0,c=0;
while(t1<=len&&t2<=len&&(c<k||a[t1]==b[t2]))
if(a[t1]!=b[t2]) c++,t1++,t2++,sum++;
else t1++,t2++,sum++;
if(ans<sum) ans=sum;
}
printf("%d\n",ans);
return 0;
}
相关文章推荐
- 【bzoj 十连测】[noip2016第一场]Problem C. Walk(dfs)
- 【bzoj 十连测】[noip2016第二场]Problem A. Divisors(暴力)
- 【bzoj 十连测】[noip2016 第一场]Problem B. Tourist Attractions(枚举)
- [BZOJbegin][NOIP十连测第一场]Tourist Attractions(图的度+bitset)
- [BZOJbegin][NOIP十连测第一场]Walk(bfs+乱搞)
- 【bzoj4721】[Noip2016]蚯蚓 乱搞
- 【bzoj 十连测】[noip2016十连测第四场]Problem A: 天空龙(数学相关)
- 【bzoj 十连测】[noip2016十连测第八场]Problem C: 幻魔皇(递推)
- bzoj 4720/Luogu 1850(期望dp)(NOIP 2016)
- BZOJ 4720 [Noip2016]换教室 (Floyd + 期望dp)
- 【bzoj4720】[NOIP2016]换教室 期望dp
- BZOJ 4720 [Noip 2016] 期望DP+最短路 解题报告
- [BZOJbegin][NOIP十连测第九场]小P的单调数列(数学相关+dp+bit)
- 【bzoj 十连测】[noip2016十连测第九场]Problem B: 小P的单调区间(最长上升子序列+树状数组)
- bzoj 4719: [Noip2016]天天爱跑步 线段树合并
- bzoj 3489: A simple rmq problem k-d树思想大暴力
- 【bzoj 十连测】[noip2016十连测第五场]Problem A: simple(bfs)
- 【noip 2016】 组合数问题(problem)
- 洛谷 1600 [NOIP2016] 天天爱跑步 树链剖分+桶 (暴力+正解)
- BZOJ P4720[Noip2016]换教室____solution