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 ...
随机推荐
- dedecms织梦让channelartlist标签支持currentstyle属性
打开include\taglib\channelartlist.lib.php 大约93行 找到: $pv->Fields['typeurl'] = GetOneTypeUrlA($typei ...
- 第9月第15天 设计模式 adapter mvc
1. 有一道iOS面试题,iOS中都有什么设计模式?很少有答案说包括adapter. gof 书中adapter模式有以下内容: 实现: ... b ) 使 用 代 理 对 象 在这种方法中, T r ...
- 第6月第4天 AVMutableComposition AVMutableVideoComposition
1. AVMutableComposition is a mutable subclass of AVComposition you use when you want to create a new ...
- [MySQL 5.6] GTID实现、运维变化及存在的bug
[MySQL 5.6] GTID实现.运维变化及存在的bug http://www.tuicool.com/articles/NjqQju 由于之前没太多深入关注gtid,这里给自己补补课,本文是我看 ...
- deeplearning.ai学习LSTM
一.LSTM架构与公式 这里的a<t>表示的就是原始输出,y<t>表示的就是经过softmax的输出,c<t>相当于状态.u(update)代表是输入门,f代表遗忘 ...
- redhat本地yum源配置
/dev/sr0是光驱的设备名,/dev/cdrom代表光驱 /dev/sr0 与/dev/cdrom /dev/cdrom 只是一个到sr0的符号链接 mount /dev/sr0 /mnt ...
- Windows下设置oracle数据库定时备份
1编写备份脚本 echo backup oracle database...... echo %~dp0 set file_dir=%~dp0 echo backup time...... set & ...
- C#: +(特性 ) + Attitude C#(类)前面或者(方法)前面 (中括号)定义
首先要说的是,可能一些刚接触C#的朋友常常容易把属性(Property)跟特性(Attribute)弄混淆,其实这是两种不同的东西.属性就是面向对象思想里所说的封装在类里面的数据字段,其形式为: 1: ...
- cat集成项目所遇到的一些坑
第一个问题:(jar包依赖冲突) 启动报错,直接贴log zhengxin-third-shanghai-cis [2017-08-21 14:17:49] 56231 WARN [main] - A ...
- Error:The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location:
在Android studio 或者intellij idea中新创建一个项目或者打开一个存在的项目时,有时候会出现Error:The supplied javaHome seems to be in ...