Codeforces Round #272 (Div. 1) Problem C. Dreamoon and Strings
1 second
256 megabytes
standard input
standard output
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 froms. Dreamoon wants to know
for all x from 0 to |s| where |s| denotes the length of string s.
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.
Print |s| + 1 space-separated integers in a single line representing the
for all x from 0 to |s|.
aaaaa
aa
2 2 1 1 0 0
axbaxxb
ab
0 1 1 2 1 1 0 0
For the first sample, the corresponding optimal values of s' after removal 0 through |s| = 5 characters from s are {"aaaaa", "aaaa","aaa", "aa", "a", ""}.
For the second sample, possible corresponding optimal values of s' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab","a", ""}.
题解报告:
几天后补上
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int maxn = 2e3 + ;
char s[maxn],p[maxn];
int errorcode,ans[maxn]; inline void updata(int & x ,int v){x=min(x,v);} int main(int argc,char *argv[])
{
scanf("%s%s",s+,p+);
int l1 = strlen(s+),l2=strlen(p+);
int dp[l1+][l2+][l1/l2+],shang=l1/l2+;
memset(dp,0x3f,sizeof(dp));errorcode=dp[][][];dp[][][]=;memset(ans,,sizeof(ans));
for(int i = ; i < l1 ; ++ i)
for(int j = ; j < l2 ; ++ j)
for(int k = ; k <= shang ; ++ k)
if(dp[i][j][k]!=errorcode)
{
if(j==) updata(dp[i+][j][k],dp[i][j][k]);
else updata(dp[i+][j][k],dp[i][j][k]+);
if(s[i+]==p[j+])
{
if(j==l2-)
updata(dp[i+][][k+],dp[i][j][k]);
else
updata(dp[i+][j+][k],dp[i][j][k]);
}
else
{
updata(dp[i+][][k],dp[i][j][k]);
}
}
for(int j = ; j <= l2 ; ++ j)
for(int k = ; k <= shang ; ++ k)
if(dp[l1][j][k] != errorcode)
{
int v = dp[l1][j][k];
ans[v] = max(ans[v],k);
}
for(int i = ; i <= l1 ; ++ i)
if(ans[i])
{
for(int j = i + ; j <= l1 ; ++ j)
ans[j]=max(ans[j],min((l1-j)/l2,ans[i]));
}
printf("%d",ans[]);
for(int i = ; i <= l1 ; ++ i) printf(" %d",ans[i]);printf("\n");
return ;
}
Codeforces Round #272 (Div. 1) Problem C. Dreamoon and Strings的更多相关文章
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- 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)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #272 (Div. 1)C(字符串DP)
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 ...
随机推荐
- Java[4] Jetty工作原理介绍(转)
转自:https://www.ibm.com/developerworks/cn/java/j-lo-jetty/ Jetty 的工作原理以及与 Tomcat 的比较 Jetty 应该是目前最活跃也是 ...
- UIWebView加载html 图片大小自适应的方法汇总
方法一 处理HTMLString的方法: NSString *htmls = [NSString stringWithFormat:@"<html> \n" " ...
- MATLAB获取“非免驱的相机或者摄像头”的图像数据
Image Acquisition Toolbox™ Adaptor Kit 图像採集工具箱 当要使用MATLAB获取"非免驱的相机或者摄像头"的图像数据时,须要开发一个插件,MA ...
- HBase学习(十四)LINUX下用Eclipse构建HBase开发环境
Eclipse,HBase版本号眼下没有发现须要特别指定 1:从HBase集群中复制一份Hbase部署文件,放置在开发端某一文件夹下(如在/app/hadoop/hbase096文件夹下). 2:在e ...
- 基于MFC的socket编程(异步非阻塞通信)
对于许多初学者来说,网络通信程序的开发,普遍的一个现象就是觉得难以入手.许多概念,诸如:同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)等,初学者往往迷惑不清, ...
- C++中的static成员
C++中的static 成员永远是我心中的痛,记了好多次了,但是今天在项目中依然忘记了,今天写下来,方便以后不用再去Baidu.google搜索了. 在头文件中声明静态成员 static int i; ...
- 定时改变App主题的方案
1.将接口返回的图片缓存到本地,由于写data到本地是耗时操作,为了不阻塞主线程,可开启子线程来做此操作 dispatch_queue_t queue = dispatch_queue_create( ...
- 关于Discuz!nt论坛编辑器图片上传bug,flash域的问题
正在整discuz!nt,现在没有什么人弄了把? 上个星期突然来了个bug,搞死我了,论坛图片不能上传,上传卡在100%没反应了,于是我发现ajax发送到AttachUpload.cs时queryst ...
- POI创建Excle
1.导包 2.Demo Workbook wb=new HSSFWorkbook();//创建工作空间 Sheet sh= wb.createSheet("工作表1");//创建工 ...
- (原)ubuntu下使用ftp软件
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6121663.html 参考网址: http://tieba.baidu.com/p/387426074 ...