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

Input
The first line of input contains an positive integer T(T<=10) indicating the number of test cases.
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.
Output
For each test,Output a line.If can output "True",else output "False".
Sample Input
3
2 3 7
yjqqaq
claris
2 2 7
popoqqq
fwwf
1 3 3
aaa
Sample Output
False
True
True
 
题解:
(多重背包都快不会打了我已经完蛋了)
这道题相对来说还是比较裸的。先用manacher计算出每种长度回文串出现的个数。
在将长度视为物品跑一个多重背包即可。
关于这里的背包,我们可以设f[i][j]为一个bool滚动数组,表示构造长度为i的串用了j个子串能不能成立。
那么显然3层循环即可。我打的是二进制分解然后01背包(其实是因为单调队列不会)
代码见下:
 #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的更多相关文章

  1. HDU 5677 ztr loves substring(Manacher+dp+二进制分解)

    题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...

  2. HDU 5677 ztr loves substring(回文串加多重背包)

    ztr loves substring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  3. hdu 5677 ztr loves substring 多重背包

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...

  4. HDU 5677 ztr loves substring

    Manacher+二维费用多重背包 二进制优化 这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解. 多重背包做的时候需要二进制优化. #include< ...

  5. HDU 5675 ztr loves math (数学推导)

    ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...

  6. HDU 5676 ztr loves lucky numbers (模拟)

    ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...

  7. HDU 5675 ztr loves math

    ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  8. hdu 5676 ztr loves lucky numbers(dfs+离线)

    Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...

  9. hdu 5675 ztr loves math(数学技巧)

    Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...

随机推荐

  1. day1 函数 (独立功能代码块)

    1.引入函数 2.函数执行过程 4.带参数的函数 5.带返回值的函数 6. 多个返回值 (return a,b,c)元组 7.4种函数 1.引入函数 独立功能代码块 ---> 封装 ----&g ...

  2. TMDXEVM6678L EVM开发板初使用(1)

    1. 板子上电风扇转个不停,震动很大. 2. 有点懵逼,第一步干啥,首先安装板子的软件开发包,资料下载地址http://www2.advantech.com/Support/TI-EVM/6678le ...

  3. Maven学习(五)-----如何从Maven远程存储库下载?

    如何从Maven远程存储库下载? 根据 Apache Maven 的说明: Downloading in Maven is triggered by a project declaring a dep ...

  4. Selenium2+python自动化-操作浏览器基本方法

    前言 从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可视化工具,我们要学的是webdriver框架的A ...

  5. selenium webdriver API详解(一)

    本系列主要讲解webdriver常用的API使用方法(注意:使用前请确认环境是否安装成功,浏览器驱动是否与谷歌浏览器版本对应) 一:打开某个网址:get() from selenium import ...

  6. Jupyter 安装并配置工作路径[转]

    1.通过python的pip方式安装jupyterpython和pip都安装好后,通过cmd进入命令提示窗口,找到python安装目录下的Script目录,例如我的是路径是:C:\Program Fi ...

  7. python终端计算器,还有没其他方法?

    import sysdef lt(a, b, c ): if b == "+": return int(a)+int(c) elif b == "-": ret ...

  8. 好用的MarkDown编辑器

    MarkDown是编写文档非常有用的一个好工具

  9. .net core 2.1.3可能引发Could not load file or assembly XXXXX的错误

    参考文档: https://github.com/aspnet/Home/issues/3503 写在前面 感觉自己现在干的活离开发越来越远了啊,不过也很好,每天能学到不少东西,中文的,英文的,永远也 ...

  10. Python基础灬文件常用操作

    文件常用操作 文件内建函数和方法 open() :打开文件 read():输入 readline():输入一行 seek():文件内移动 write():输出 close():关闭文件 写文件writ ...