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 ...
随机推荐
- 数据库类型与JDBC TYPE 和Java类型对应关系
https://blog.csdn.net/seelye/article/details/40105969
- bzoj千题计划273:bzoj4710: [Jsoi2011]分特产
http://www.lydsy.com/JudgeOnline/problem.php?id=4710 答案=总方案数-不合法方案数 f[i][j] 前i种特产分给j个人(可能有人没有分到特产)的总 ...
- 20155225 2016-2017-2 《Java程序设计》第八周学习总结
20155225 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 通用API 日志API 国际化基础 规则表达式 JDK8增强功能 教材学习中的问题和解决过程 ...
- MYSQL导入数据出现The MySQL server is running with the --secure-file-priv
MYSQL导入数据出现The MySQL server is running with the --secure-file-priv option so it cannot execute this ...
- git与代码托管工具
1.git初识 git是一个版本管理工具,用来管理项目的不同的版本,记录下不同的提交记录,git还可以构建不同的分支,用来给不同的人来推送使用. 推荐的git教程:https://www.cnblog ...
- 图解USB协议之一 枚举过程【转】
转自:http://blog.csdn.net/myarrow/article/details/8270060 0. 枚举流程 • 连接了设备的 HUB 在 HOST 查询其状态改变端点 时返回对应的 ...
- C# sha256 加密算法
C# 非对称加密 public string sha256(string data) { byte[] bytes = Encoding.UTF8.GetBytes(data); byte[] has ...
- 【译】EntityFramework6与EntityFrameworkCore的区别
EntityFramework6 EF6 是一个久经考验的数据库访问技术,发展多年,拥有许多特性,并且成熟稳定.2008年EF作为 .Net 3.5 Sp1 和Visual Studio 2008 S ...
- 『记录』Android参考资料
欢迎留言推荐好的教程.资料.博客及作者等. 『记录』Android参考资料 1.前期环境 Android Studio使用Git Android Studio快捷键总结 Android Studio及 ...
- easyui tree:根据属性格式化树节点名称
$('#resourceTree').tree({ method : 'post', animate : true, onContextMenu : function(e, node) { e.pre ...