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 ...
随机推荐
- [每日一题] OCP1z0-047 :2013-08-05 SELECT语句――列的表达式
按题意操作如下: hr@MYDB> SELECT first_name,salary,salary*12+salary*12*0.5 "ANNUAL SALARY + BONUS&qu ...
- MySQL 遇到的问题:在服务里找不到自己的 MySQL,以及在命令行窗口中运行服务出现的问题。
1.用数据库的时候在服务里找不到自己的 MySQL ,于是就想用命令行窗口去运行. ①.在开始里,键入 cmd ,打开命令行窗口. ②.输入:mysql -u root -p 回车,这时会提示请输入密 ...
- Python爬虫实战(二)
本来晚上是准备写贴吧爬虫的,但是在分析页面时就遇到了大麻烦!选取了某个帖子,在爬取的时候,发现正则匹配不全..很尴尬!!先来看看吧, #!/usr/bin/env python # -*- codin ...
- 复合命令A等效于$a
时间:2014.06.28 地点:基地 ------------------------------------------------------------------------------- ...
- 命令行修改linux系统IP
修改配置文件/etc/sysconfig/network-scrips/ifcfg-eth0.因为机子启动的时候加载的就是这个文件的配置参数.对这个文件进行修改: [root@localhost ...
- django: db - many to many
本讲介绍数据库多对多关系,代码样例继前文使用. 一,在 blog/models.py 中创建对象: # Many-To-Many Example : Authors vs Books class Au ...
- border和outline区别
border和outline区别: border支持box-sizing: border-box,当有边距时,是新增了边框后在按照以前的边距处理 outline不支持box-sizing: borde ...
- firefox 不能显示 glyphicons 字体
折腾了很久才发现是firefox 不能跨域下载相应的字体文件,将bootstrap相应的css文件和字体文件copy到调用的项目里,问题才得以解决.
- (转)SQL Server 2008将数据导出为脚本 [SQL Server]
之前我们要将一个表中的数据导出为脚本,那么只有在网上找一个导出数据的Script,然后运行就可以导出数据脚本了.现在在SQL Server 2008的Management Studio中增加了一个新特 ...
- 干货--微信公众平台客户端调试工具-初试WPF开发
本工具可以由任意一个开发微信公众平台的开发者使用,虽然它本身使用WPF(C#)开发的,但是并不受你想调试的服务所用的语言的影响. 之前一直在做微信公众平台开发,客户端调试是必须做的事情,一直以来都是用 ...