Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings
题目连接:
http://www.codeforces.com/contest/476/problem/E
Description
Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible.
More formally, let's define as maximum value of over all s' that can be obtained by removing exactly x characters from s. Dreamoon wants to know for all x from 0 to |s| where |s| denotes the length of string s.
Input
The first line of the input contains the string s (1 ≤ |s| ≤ 2 000).
The second line of the input contains the string p (1 ≤ |p| ≤ 500).
Both strings will only consist of lower case English letters.
Output
Print |s| + 1 space-separated integers in a single line representing the for all x from 0 to |s|.
Sample Input
aaaaa
aa
Sample Output
2 2 1 1 0 0
Hint
题意
给你一个串S,和另外一个串P
把k从0到|S|枚举,然后问你去掉k个字符后,s串里面最多有多少个不重叠的p字符串
题解:
dp,dp[i][j]表示考虑到第i个位置,去掉了j个字符的最大值
然后我们对于每一个位置,先暴力找到最少去掉多少个,才能加一,然后暴力去转移这个玩意儿就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
char s1[maxn],s2[maxn];
int dp[maxn][maxn];
int len1,len2;
int solve(int x)
{
if(x<len2)return maxn;
int a=x,b=len2,tmp=0;
while(a&&b)
{
if(s1[a]==s2[b])a--,b--;
else tmp++,a--;
}
if(b==0)return tmp;
else return maxn;
}
int main()
{
scanf("%s%s",s1+1,s2+1);
len1 = strlen(s1+1);
len2 = strlen(s2+1);
for(int i=0;i<=len1;i++)
for(int j=0;j<=len1;j++)
if(j>i)dp[i][j]=-3000;
for(int i=1;i<=len1;i++)
{
int x=solve(i);
for(int k=0;k<=len1;k++)
dp[i][k]=max(dp[i][k],dp[i-1][k]);
for(int k=0;k<=len1;k++)if(x<=k)
dp[i][k]=max(dp[i][k],dp[i-x-len2][k-x]+1);
}
for(int i=0;i<=len1;i++)
printf("%d ",dp[len1][i]);
printf("\n");
}
Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划的更多相关文章
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp
B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)
题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...
- Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums
http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...
- Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi
http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...
- Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs
http://codeforces.com/contest/476/problem/A A. Dreamoon and Stairs time limit per test 1 second memo ...
- Codeforces Round #272 (Div. 2)C. Dreamoon and Sums 数学推公式
C. Dreamoon and Sums Dreamoon loves summing up something for no reason. One day he obtains two int ...
随机推荐
- Carmichael Numbers (Uva No.10006) -- 快速幂运算_埃氏筛法_打表
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> ...
- go语言学习之路(一)Hello World
为什么要使用 Go 语言?Go 语言的优势在哪里? 1.部署简单. 2.并发性好. 3.良好的语言设计. 4.执行性能好. Go环境搭建 Golang下载 国外镜像 https://www.gola ...
- ASP.NET实现二维码(QRCode)的创建和读取
一.项目引用QRCode的DLL文件(ThoughtWorks.QRCode.dll) 二.ASPX页面(两个jquery的js文件请自行去官网下载): [html] <html xm ...
- 20155235 2016-2017-2 《Java程序设计》第8周学习总结
20155235 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 第十四章 NIO与NIO2 认识NIO NIO概述 Channel架构与操作 Buffer架 ...
- shell ssh 批量执行
ssh 批量执行命令 #版本1 #!/bin/bash while read line do Ip=`echo $line|awk '{print $1}'` Passwd=`echo $line|a ...
- Android getScrollX()详解
在开发中相信大家在自定义View时会时不时的使用getScrollX()方法,为了便于之后的开发工作,本篇博客主要记录了我对getScrollX()方法的理解. getScrollX:Return t ...
- if语句引起的bug
最近维护高手留下的api项目,客户端反馈一个bug过来,然后查找到可能出错的代码位置,是一个if语句,乍一看好像没什么问题,代码如下: if (company.UserId != userId || ...
- MySQL5.7 GTID在线开启与关闭【转】
当前场景 当前某些业务还有未开启GTID服务组,升级5.7后,如何检测是否符合开启GTID条件,如何在线修改切换使用GTID:已经升级5.7后,已经开启GTID,如何快速回滚后退: 线上gtid如 ...
- 高可用的MongoDB集群【转】
刚接触MongoDB,就要用到它的集群,只能硬着头皮短时间去看文档和尝试自行搭建.迁移历史数据更是让人恼火,近100G的数据文件,导入.清理垃圾数据执行的速度蜗牛一样的慢.趁着这个时间,把这几天关于M ...
- javascript 模拟按键点击提交
上代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...