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

思路:二维费用的

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = ;
  4. const int INF = 0x3f3f3f3f;
  5. int Ma[N << ], Mp[N << ];
  6. char s[N];
  7. int cnt[N];
  8.  
  9. void manacher(char s[], int len) {
  10. int l = ;
  11. Ma[l++] = '$';
  12. Ma[l++] = '#';
  13. for(int i = ; i < len; ++i)
  14. {
  15. Ma[l++] = s[i];
  16. Ma[l++] = '#';
  17. }
  18. Ma[l] = ;
  19. int mx = , id = ;
  20. for(int i = ; i < l; ++i)
  21. {
  22. Mp[i] = mx > i ? min(Mp[ * id - i], mx - i) : ;
  23. while(Ma[ i + Mp[i] ] == Ma[ i - Mp[i] ]) Mp[i]++;
  24. if(i + Mp[i] > mx) mx = i + Mp[i], id = i;
  25. }
  26. for(int i = ; i < l; ++i) if(Mp[i] > ) {
  27. int p;
  28. if(Mp[i] & ) p = ; else p = ;
  29. for(int j = p; j < Mp[i]; j += ) cnt[j]++;
  30. }
  31. }
  32. int dp[N][N];
  33. void Dp1(int v, int k, int l) {
  34. for(int i = v; i <= l; ++i)
  35. for(int j = ; j <= k; ++j)
  36. if(dp[i - v][j - ]) dp[i][j] = ;
  37. }
  38. void Dp2(int v, int num, int k, int l) {
  39. for(int i = l; i >= v; --i)
  40. for(int j = k; j >= num; --j)
  41. if(dp[i - v][j - num]) dp[i][j] = ;
  42. }
  43.  
  44. void to(int x, int k, int l) {
  45. if(cnt[x] >= k && x * cnt[x] >= l) Dp1(x, k, l);
  46. else {
  47. int s = , tot = cnt[x];
  48. while(s < tot) {
  49. Dp2(x * s, s, k, l);
  50. tot -= s;
  51. s <<= ;
  52. }
  53. Dp2(tot * x, tot, k, l);
  54. }
  55. }
  56. bool solve(int k, int l) {
  57. memset(dp, , sizeof dp);
  58. dp[][] = ;
  59. for(int i = ; i <= ; ++i) if(cnt[i]) to(i, k, l);
  60. if(dp[l][k]) return true;
  61. return false;
  62. }
  63. int main() {
  64. // freopen("in", "r", stdin);
  65. int _; scanf("%d", &_);
  66. while(_ --) {
  67. int n, k, l;
  68. scanf("%d%d%d", &n, &k, &l);
  69. memset(cnt, , sizeof cnt);
  70. for(int i = ; i < n; ++i) {
  71. scanf("%s", s);
  72. int len = strlen(s);
  73. manacher(s, len);
  74. }
  75. if(solve(k, l)) puts("True");
  76. else puts("False");
  77. }
  78. return ;
  79. }

,且二维都要求恰好装满,那么初始化[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. python基础2(数据类型、数据运算、for循环、while循环、列表)

    1.数据类型 python使用对象模型来存储数据,每一个数据类型都有一个内置的类,每新建一个数据,实际就是一个对象,即所有数据都是对象. 对象的3个特性: 身份:即内存地址,可以用id()来获取 类型 ...

  2. Windows远程数据同步工具cwRsync

    1. cwRsync简介cwRsync是Rsync在Windows上的实现版本,Rsync通过使用特定算法的文件传输技术,可以在网络上传输只修改了的文件.cwRsync主要用于Windows上的远程文 ...

  3. Container View 使用小技巧

    一.传值,顺传 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { TVC *vc = segue.destin ...

  4. Excel 实用技巧之一

    1.在单元格内换行: Alt+Enter 2.合并其他单元格文字并换行: A1&char(10)&B1 3.Excel计算样本估算总体方差:STDEV/STDEVA(),分母为n-1. ...

  5. java生产者/消费者模式实现——一生产者一消费者(操作值)

    胶多不粘话多不甜,直接上代码: 生产者类: /** * Created by 51304 on 2016/2/28. */ public class P { private String lock; ...

  6. sql语句,多个表之间,通过相同内容字段的联合查询

    1 , select j.id,         jt.Name,        j.ApproveType ,         j.ProductCode,         j.CustomerCo ...

  7. 欢迎加入threejs

    Threejs is the coolest graphics rendering engine I have ever seen, so what is threejs, Now, we have ...

  8. 转:mysql根据经纬度查找排序

    一.MySql不使用空间函数,简单版 1.粗算,根据场景得到一个range,计算经纬度,得到的是一个矩形区域(A),不精确,但是已经有范围这个雏形了,最容易实现的方式之一. 1 2 3 4 5 6 w ...

  9. oracle查询某一个字段的数量总和

    select count(*) from (select count(*) from 表名称 group by 多种数据量 ) 表名; 举个栗子: 比如说我有一个数据类型的字段, 里面有很多种的数据类 ...

  10. 【GoLang】golang 的精髓--流水线,对现实世界的完美模拟

    直接上代码: package main import ( "fmt" "runtime" "strconv" "sync" ...