Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 178    Accepted Submission(s): 93

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
 
Source

思路:二维费用的

#include <bits/stdc++.h>
using namespace std;
const int N = ;
const int INF = 0x3f3f3f3f;
int Ma[N << ], Mp[N << ];
char s[N];
int cnt[N]; void manacher(char s[], int len) {
int l = ;
Ma[l++] = '$';
Ma[l++] = '#';
for(int i = ; i < len; ++i)
{
Ma[l++] = s[i];
Ma[l++] = '#';
}
Ma[l] = ;
int mx = , id = ;
for(int i = ; i < l; ++i)
{
Mp[i] = mx > i ? min(Mp[ * id - i], mx - i) : ;
while(Ma[ i + Mp[i] ] == Ma[ i - Mp[i] ]) Mp[i]++;
if(i + Mp[i] > mx) mx = i + Mp[i], id = i;
}
for(int i = ; i < l; ++i) if(Mp[i] > ) {
int p;
if(Mp[i] & ) p = ; else p = ;
for(int j = p; j < Mp[i]; j += ) cnt[j]++;
}
}
int dp[N][N];
void Dp1(int v, int k, int l) {
for(int i = v; i <= l; ++i)
for(int j = ; j <= k; ++j)
if(dp[i - v][j - ]) dp[i][j] = ;
}
void Dp2(int v, int num, int k, int l) {
for(int i = l; i >= v; --i)
for(int j = k; j >= num; --j)
if(dp[i - v][j - num]) dp[i][j] = ;
} void to(int x, int k, int l) {
if(cnt[x] >= k && x * cnt[x] >= l) Dp1(x, k, l);
else {
int s = , tot = cnt[x];
while(s < tot) {
Dp2(x * s, s, k, l);
tot -= s;
s <<= ;
}
Dp2(tot * x, tot, k, l);
}
}
bool solve(int k, int l) {
memset(dp, , sizeof dp);
dp[][] = ;
for(int i = ; i <= ; ++i) if(cnt[i]) to(i, k, l);
if(dp[l][k]) return true;
return false;
}
int main() {
// freopen("in", "r", stdin);
int _; scanf("%d", &_);
while(_ --) {
int n, k, l;
scanf("%d%d%d", &n, &k, &l);
memset(cnt, , sizeof cnt);
for(int i = ; i < n; ++i) {
scanf("%s", s);
int len = strlen(s);
manacher(s, len);
}
if(solve(k, l)) puts("True");
else puts("False");
}
return ;
}

,且二维都要求恰好装满,那么初始化[0][0]能满足,其它状态都不满足

hdu 5677 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

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

  4. [HDU5677]ztr loves substring

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

  5. HDU 3732 Ahui Writes Word(多重背包)

    HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...

  6. HDU 2082 找单词 (多重背包)

    题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...

  7. HDU 5445 Food Problem(多重背包+二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...

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

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

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

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

随机推荐

  1. ztree.js的使用整理

    /** 配置:知识点管理 */ var setting = { view: { showIcon: false, addDiyDom: addPrevDom, addHoverDom: addHove ...

  2. web service 学习

    是什么? 是一种远程调用技术,这种技术提供一些接口,这些接口实现让客户端和服务端进行通信和数据交换,并且让通信和交换与平台和开发语言无关.也可以说是提供了许多函数.客户端调用服务端的函数. 远程调用: ...

  3. strace追踪未开始或者来不及捕获pid的进程(译)

    我的个人博客网站最近被攻击了,被用来发送一些垃圾邮件.但是我不知道这个进程是怎么来的,用top查看发现一个不知道干什么的perl脚本,决定给用strace查看一下. strace可以追踪一个进程的系统 ...

  4. [ios基础]IOS应用程序的生命周期问题

    —程序的生命周期         a.程序的生命周期是指应用程序启动到应用程序结束整个阶段的全过程         b.每一个IOS应用程序都包含一个UIApplication对象,IOS系统通过该U ...

  5. Silicon C8051F340之GPIO口配置与使用

    一.背景: 很久前用过C8051,现在有相关需求需要重新使用C8051,然后发现一年前开发的相关经验都忘得 基本上差不多了.连最基本的GPIO口配置还得重新来看手册,所以有此文,做个记录,以备下次快速 ...

  6. 利用 PhpStorm、Idea 等 IDE 如何 运行/调试 Go 程序 ?

    以自己常用的 PhpStorm 为例 第一步:下载安装 Go插件 File -> Settings -> Plugins -> 输入关键字:Go 第二步:新建 Go项目 File - ...

  7. Linux下,如何给PHP安装pdo_mysql扩展

    下载了一个免费开源的广告系统(openadserver),在Linux上安装时,提示要安装 pdo_mysql 扩展,先前有过编译安装 soap扩展 的经历,今天要编译安装 pdo_mysql 扩展, ...

  8. SSI指令

    1.SSI定义 SSI是英文Server Side Includes的缩写, 即“服务器端包含”或“服务器端嵌入”技术. SSI在HTML文件中,可以通过注释行调用的命令或指针,是一种基于服务器端的网 ...

  9. touch移动触屏滑动事件

    移动端触屏滑动的效果其实就是图片轮播,在PC的页面上很好实现,绑定click和mouseover等事件来完成.但是在移动设备上,要实现这种轮播的效果,就需要用到核心的touch事件.处理touch事件 ...

  10. css实现翻页效果

    如图,鼠标移动到图上,实现右上角翻页的效果,本例主要border边框的设置. 一.基本概念 <html> <head> <style> #demo{ width:0 ...