[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 ...
随机推荐
- 通知的多线程问题 iOS
发送通知在子线程,接受也在子线程.如果子线程操作UI,会打印一推日志,告诉我们应该主线程操作.
- Linux大全
Linux 基本指令介紹 一定要先學會的指令:ls, more, cd, pwd, rpm, ifconfig, find 登入與登出(開機與關機):telnet, login, exit, sh ...
- 【UGUI】 (一)------- 放大镜
在许多游戏或应用中,我们常常看到放大镜的身影,而在Unity里面,制作一个简易的放大镜是非常简单的. 一. 创建一个3DObject 创建一个Cube或者 Cylinder,这里为了更像放大镜一 ...
- OpenLDAP介绍
首先LDAP是一个轻量级的产品(LightWeight),是一个Directory(D),存取的协议(Access Protocol). 我要着重指出,LDAP是一个数据库,但是又不是一个数据库.说他 ...
- 论文笔记:Visual Object Tracking based on Adaptive Siamese and Motion Estimation Network
Visual Object Tracking based on Adaptive Siamese and Motion Estimation 本文提出一种利用上一帧目标位置坐标,在本帧中找出目标可能出 ...
- 53. [LeetCode] Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- 用Tensorflow完成简单的线性回归模型
思路:在数据上选择一条直线y=Wx+b,在这条直线上附件随机生成一些数据点如下图,让TensorFlow建立回归模型,去学习什么样的W和b能更好去拟合这些数据点. 1)随机生成1000个数据点,围绕在 ...
- [leetcode-914-X of a Kind in a Deck of Cards]
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- 20172311-ASL测试 2018-1938872补充博客
20172311-ASL测试 2018-1938872补充博客 课程:<程序设计与数据结构> 班级: 1723 姓名: 赵晓海 学号: 20172311 实验教师:王志强老师 测试日期:2 ...
- Java 通过先序中序序列生成二叉树
题目 二叉树的前序以及后续序列,以空格间隔每个元素,重构二叉树,最后输出二叉树的三种遍历方式的序列以验证. 输入: 1 2 3 4 5 6 7 8 9 10 3 2 5 4 1 7 8 6 10 9 ...