C. Dreamoon and Strings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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 test(s)
input
aaaaa
aa
output
2 2 1 1 0 0
input
axbaxxb
ab
output
0 1 1 2 1 1 0 0
Note

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的更多相关文章

  1. Codeforces Round #272 (Div. 2) 题解

    Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...

  2. 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 ...

  3. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  4. 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 ...

  5. Codeforces Round #272 (Div. 2)AK报告

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. 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 ...

  7. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  8. 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 ...

  9. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

随机推荐

  1. Java[1] Java学习书籍汇总(转)

    原文:http://www.cnblogs.com/hyl8218/p/5067000.html 学习的最好途径就是看书“,这是我自己学习并且小有了一定的积累之后的第一体会.个人认为看书有两点好处: ...

  2. SecureCRT7.3和SecureFX7.3的MAC下破解

    破解脚本:http://files.cnblogs.com/files/jieyuefeng/SecureCRTFX_mac_crack.zip 破解方法: sudo perl ~/Downloads ...

  3. 一种调用opencv库的C++工程通用的Makefile模板

    第一次自己写makefile,记录一下 #Compilers #CXX=/opt/compiler/gcc-/bin/g++ CXX = g++ #Includes INCLUDE_FLAGS = - ...

  4. 【性能优化】优化笔记之一:图像RGB与YUV转换优化

    本文主要介绍如何优化您自己的CODE,实现软件的加速.我们一个图象模式识别的项目,需要将RGB格式的彩色图像先转换成黑白图像.图像转换的公式如下: Y = 0.299 * R + 0.587 * G ...

  5. EA+svn实现UML的版本号控制

    一.安装软件 1.VisualSvn Server svnserver 2.Tortoise Svn svnclient 3.Slik-Subversion-1.7.8-x64版本号控制插件 4.En ...

  6. 类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast

    一.static_cast 对于类型转换,我们常常这么做: (type) expression 引进了static_cast类型转换操作符后,我们只需这样做: static_cast<type& ...

  7. Java基础知识强化41:StringBuffer类之StringBuffer的反转功能

    1. StringBuffer 的反转功能: public StringBuffer reverse(): 2. 案例演示: package cn.itcast_05; /* * StringBuff ...

  8. LSI SAS 3008配置操作

    配置 LSI SAS 3008 介绍LSISAS3008的配置操作. 4.1 登录CU界面 介绍登录LSISAS3008的CU配置界面的方法. 4.2 创建RAID 介绍在LSISAS3008扣卡上创 ...

  9. 新唐Cortex-M0微控制器的省电管理

    新唐科技的NUC1xx包含NUC101.NUC100.NUC120.NUC130和NUC140,是以ARM Cortex-M0为核心的32位微控制器(MCU),经由不同时钟的设定,最高可以达到 50M ...

  10. php 多维数组如何用foreach遍历修改其中的一个值

    数组: array(6) { [0]=> array(11) { ["id"]=> string(2) "76" ["topic_id&q ...