[HDU5677]ztr loves substring
ztr loves substring
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
ztr love reserach substring.Today ,he has n string.Now ztr want to konw,can he take out exactly k palindrome from all substring of these n string,and thrn sum of length of these k substring is L.for example string "yjqqaq".this string contains plalindromes:"y","j","q","a","q","qq","qaq".so we can choose "qq" and "qaq".
For each test case:
First line contains these positive integer N(1<=N<=100),K(1<=K<=100),L(L<=100).
The next N line,each line contains a string only contains lowercase.Guarantee even length of string won't more than L.
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int n,t,m,k,ct,mx,l;
int r[N<<],f[N][N],vis[N];
char s[N<<],str[N];
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline void manacher()
{
memset(s,,sizeof(s));
n=;m=strlen(str);
s[n++]=;s[n++]=;
for(int i=;i<m;i++)s[n++]=str[i],s[n++]=;
memset(r,,sizeof(r));ct=mx=;
for(int i=;i<n;i++)
{
if(i<mx)r[i]=min(mx-i,r[*ct-i]);
else r[i]=;
while(<=i-r[i]&&i+r[i]<n&&s[i-r[i]]==s[i+r[i]])r[i]++;
if(i+r[i]>mx)ct=i,mx=i+r[i];
int j=r[i]-;
while(j>=)vis[j]++,j-=;
}
}
int c[N*N],v[N*N],cnt;
inline bool backpack()
{
memset(f,,sizeof(f));
for(int i=;i<=l;i++)
{
int tmp=;
while(vis[i]>=tmp)
c[++cnt]=tmp*i,v[cnt]=tmp,vis[i]-=tmp,tmp<<=;
if(vis[i])
c[++cnt]=vis[i]*i,v[cnt]=vis[i];
}
f[][]=;
for(int u=;u<=cnt;u++)
for(int i=l;i>=c[u];i--)
for(int j=k;j>=v[u];j--)
f[i][j]|=f[i-c[u]][j-v[u]];
return f[l][k];
}
int main()
{
int cnt;scanf("%d",&cnt);
while(cnt--)
{
scanf("%d%d%d",&t,&k,&l);
memset(vis,,sizeof(vis));
for(int i=;i<=t;i++)
scanf("%s",str),manacher();
if(backpack())printf("True\n");
else printf("False\n");
}
}
HDU5677
[HDU5677]ztr loves substring的更多相关文章
- HDU 5677 ztr loves substring(Manacher+dp+二进制分解)
题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...
- HDU 5677 ztr loves substring(回文串加多重背包)
ztr loves substring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 5677 ztr loves substring 多重背包
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...
- HDU 5677 ztr loves substring
Manacher+二维费用多重背包 二进制优化 这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解. 多重背包做的时候需要二进制优化. #include< ...
- HDU 5675 ztr loves math (数学推导)
ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...
- HDU 5676 ztr loves lucky numbers (模拟)
ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...
- HDU 5675 ztr loves math
ztr loves math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- hdu 5676 ztr loves lucky numbers(dfs+离线)
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...
- hdu 5675 ztr loves math(数学技巧)
Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...
随机推荐
- 新技能get,使用PHPStorm的deployment工具
1. 工具栏 Tools - Deployment - Configuration 2. 添加一个服务端的配置信息 type 类型可以选择:FTP.local等. 填完信息别忘了点"Test ...
- cogs2554 [福利]可持久化线段树
cogs2554 [福利]可持久化线段树 原题链接 每次修改复制一遍就行了... 1A!!! // It is made by XZZ #include<cstdio> #include& ...
- php-laravel安装与使用
1.框架作用 提供了一些主体功能,方便开发者快速开发 2.PHP框架 laravel ThinkPHP 3.首先要安装composer软件 1.作用 主要管理PH ...
- Linux系统中Oracle11g数据库的安装与验证
1.查看Linux系统的位数 2.下载Oracle10g数据库软件 https://blog.csdn.net/xiezuoyong/article/details/81197688 (需要注册Ora ...
- JavaScript指定断点操作
什么是断点操作(Breakpoint action) 做前端开发的小伙伴,或许对这个断点操作不是很熟悉.不过你要是问其他语言(比如C,C++ ,C #等)的开发者,他们应该都挺熟悉断点操作,这种断点操 ...
- eos开发实践
一 下载前端代码 git clone https://github.com/baidang201/eos-todo 二 安装nodejs sudo apt-get install python-sof ...
- 如何更改Arcmap里经纬度小数点后面的位数?
customize>arcmap option>data view >round coordinate to 改成想要显示的小数位数
- hihocoder #1032 : 最长回文子串 Manacher算法
题目链接: https://hihocoder.com/problemset/problem/1032?sid=868170 最长回文子串 时间限制:1000ms内存限制:64MB 问题描述 小Hi和 ...
- HDU 5225 枚举
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- JavaScript DOM编程艺术学习笔记-第一章JavaScript简史
一,JavaScript的起源 JavaScript是Netscape与Sun公司合作开发,它是一种脚本语言,通常只能通过Web浏览器去完成一些操作.JavaScript为程序员提供了一些操控Web浏 ...