P2031 脑力达人之分割字串
字符串dp,f[i]表示主串到第i个字符,最多能分割成多少子串。
f[i]=max(f[i],f[k]+1);k是能匹配到的前一位。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.29
using namespace std;
char a[],c[][];
int n;
int la,lb;
bool flag;
int f[];
int mx;
void in(int &x)
{
int y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=x*+c-'',c=g();
x*=y;
}
void o(int x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main()
{
cin>>(a+);
la=strlen(a+);
in(n);
For(i,,n)
cin>>(c[i]+);
For(i,,la)
{
f[i]=mx;
For(j,,n)
{
flag=false;
lb=strlen(c[j]+);
if(lb<=i)
{
For(k,,lb)
if(a[i-lb+k]!=c[j][k])
{
flag=true;
break;
}
if(!flag)
f[i]=max(f[i],f[i-lb]+);
}
}
if(f[i]>mx)
mx=f[i];
}
o(f[la]);
return ;
}

P2031 脑力达人之分割字串的更多相关文章

  1. 洛谷 P2031 脑力达人之分割字串

    题目传送门 解题思路: f[i]表示到第i位可获得的最大分割次数,对于每个f[i]都可由其符合条件的前缀转移过来,条件就是当前串除了前缀的剩余字符里有所给单词,然后一看,这不是在剩余字符里找有没有所给 ...

  2. [luoguP2031] 脑力达人之分割字串(DP)

    传送门 想了个4次方算法,没想到也A了,数据真是水. 其实两个字符串匹配那部分可以用kmp优化 ——代码 #include <cstdio> #include <cstring> ...

  3. PHP 分割字串 Function 的速度比較(substr/sscanf/preg_match)---substr最快!

    固定長度的字串(假設是 06481a63041b578d702f159f520847f8), 要照固定格式做切割, 使用 PHP 要怎麼切會比較快? 註: 要將此字串切成 => 06 / 48 ...

  4. 根据token分割字串

    #include <iostream> #include <string> #include <cstring> int main() { const char * ...

  5. 字串符相关 split() 字串符分隔 substring() 提取字符串 substr()提取指定数目的字符 parseInt() 函数可解析一个字符串,并返回一个整数。

    split() 方法将字符串分割为字符串数组,并返回此数组. stringObject.split(separator,limit) 我们将按照不同的方式来分割字符串: 使用指定符号分割字符串,代码如 ...

  6. shell脚本 字串截取 正则表达式

    字串处理 子串截取方法一:使用${}表达式格式:echo ${x:起始位置:长度}(起始位置编号从0开始,可省略) 方法二:使用expr substr格式:expr substr "$x&q ...

  7. 最大公共字串LCS问题(阿里巴巴)

    给定两个串,均由最小字母组成.求这两个串的最大公共字串LCS(Longest Common Substring). 使用动态规划解决. #include <iostream> #inclu ...

  8. 编程:使用递归方式判断某个字串是否回文(Palindrome)

    Answer: import java.util.Scanner; public class Palindrome { private static int len;//全局变量整型数据 privat ...

  9. NOIP2002字串变换[BFS]

    题目描述 已知有两个字串 A$, B$ 及一组字串变换的规则(至多6个规则): A1$ -> B1$ A2$ -> B2$ 规则的含义为:在 A$中的子串 A1$ 可以变换为 B1$.A2 ...

随机推荐

  1. python - json/pickle

    # import json #将数据类型转换成字符串 # data = {"a":"123"} # a = json.dumps(data) # print(a ...

  2. ActiveMQ集成Spring使用

    现在任何一个框架的使用都会结合spring框架,quartz.cxf与平时常见的Hibernate.mybatis.Struts等都可以与spring集成起来使用,在这里研究了activemq结合sp ...

  3. sql 中的null值

    1.包含null的表达式都为空 select salary*12+nvl(bonus,0) nvl是虑空函数 2. null值永远!=null select  * from emp  where bo ...

  4. JDK8 Lambda表达式对代码的简化

    只是举个例子: public class LambdaDemo { public static String findData( String name , LambdaInterface finde ...

  5. malloc 函数详解【转】

    转自:https://www.cnblogs.com/Commence/p/5785912.html 很多学过C的人对malloc都不是很了解,知道使用malloc要加头文件,知道malloc是分配一 ...

  6. Project Euler Problem 10

    Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...

  7. sqlserver2008r2数据库关联孤立账号的方法

    重新安装mssql数据库后可能有这样的问题,     在数据还原到其他服务器时,登录名会丢失,重建非常麻烦     特別是数据库用户较多的的情况,其实这个问题解决非常简单,     sql serve ...

  8. viewpager显示图片的Adapter

    package com.ming.chiye.yishanghorse.Adapter; import android.content.Context; import android.graphics ...

  9. STM32F412应用开发笔记之九:移植FreeRTOS到F412ZG平台

    在开发实际应用系统时,我们经常需要考虑数据的实时性和多任务,嵌入式实时操作系统的出现为实现这一目的提供了很好的助力.FreeRTOS是近年来比较流行的嵌入式实时操作系统,而且是开源免费的,STM32C ...

  10. 笔记 oracle 创建联合主键

    笔记 alter table tablename add constraint unionkeyname primary key (column1,column2); 上面语句中: tablename ...