[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 ...
随机推荐
- 解决 mysql in 查询排序问题
select id,title from za_item where -- id ,) 返回的结果第一条是对应id是1000,第二条是1003. 如果我们想让结果和in里面的排序一致,可以这么做. s ...
- eclipse中编译出现错误undefined reference to `_sbrk'
1. 在eclipse中使用gcc-arm-none-eabi-7-2017-q4-major-win32编译代码的时候出现了undefined reference to `_sbrk' e:/pro ...
- 一步步带你配置IIS(包括错误分析)
今天趁着工作中的问题一下子来解决IIS配置 发布网站:点击VS发布网站 第一步:新建配置文件(我取名为webSite) : 第二步:选择发布方法并且选择把文件发布到哪里(比喻在D盘创建一个文件夹web ...
- Mysql取消SSH链接和恢复SSH链接
取消SSH链接//键入密码,链接上mysql mysql -u root -p USE MYSQL; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIF ...
- 如何快速解决MySQL 1032 主从错误
3分钟解决MySQL 1032主从错误 Part1:写在最前1032错误----现在生产库中好多数据,在从库误删了,生产库更新后找不到了,现在主从不同步了,再跳过错误也没用,因为没这条,再更新还会报错 ...
- 测试基础-http协议(转)
HTTP的特性 HTTP构建于TCP/IP协议之上,默认端口号是80 HTTP是无连接无状态的 HTTP报文 请求报文 HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规 ...
- Unity ScriptableObject自定义属性显示
1. 继承Editor,重写OnInspectorGUI方法 Editor官方文档 需求 将TestClass中intData属性和stringData按指定格式显示. 实现 定义一个测试类TestC ...
- 爬虫2.4-scrapy框架-图片分类下载
目录 scrapy框架-图片下载 1 传统下载方法: 2 scrapy框架的下载方法 3 分类下载完整代码 scrapy框架-图片下载 python小知识: map函数:将一个可迭代对象的每个值,依次 ...
- PHPCMS的产品筛选功能
如下图所示功能: 首先,用下面这些代码替换掉phpcms/libs/functions/extention.func.php的内容 <?php /** * extention.func.php ...
- PHP性能优化 -实战篇
借助xhprof 工具分析PHP性能 XHPorf(源自Fackbook 的PHP性能分析工具) 实战 通过分析Wordpress程序,做优化! 优化 找到需要优化的函数 grep 'impo ...