hdu 5677 ztr loves substring 多重背包
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 178 Accepted Submission(s): 93
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 <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 多重背包的更多相关文章
- 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
Manacher+二维费用多重背包 二进制优化 这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解. 多重背包做的时候需要二进制优化. #include< ...
- [HDU5677]ztr loves substring
ztr loves substring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 3732 Ahui Writes Word(多重背包)
HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...
- HDU 2082 找单词 (多重背包)
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...
- HDU 5445 Food Problem(多重背包+二进制优化)
http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...
- 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 ...
随机推荐
- python基础2(数据类型、数据运算、for循环、while循环、列表)
1.数据类型 python使用对象模型来存储数据,每一个数据类型都有一个内置的类,每新建一个数据,实际就是一个对象,即所有数据都是对象. 对象的3个特性: 身份:即内存地址,可以用id()来获取 类型 ...
- Windows远程数据同步工具cwRsync
1. cwRsync简介cwRsync是Rsync在Windows上的实现版本,Rsync通过使用特定算法的文件传输技术,可以在网络上传输只修改了的文件.cwRsync主要用于Windows上的远程文 ...
- Container View 使用小技巧
一.传值,顺传 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { TVC *vc = segue.destin ...
- Excel 实用技巧之一
1.在单元格内换行: Alt+Enter 2.合并其他单元格文字并换行: A1&char(10)&B1 3.Excel计算样本估算总体方差:STDEV/STDEVA(),分母为n-1. ...
- java生产者/消费者模式实现——一生产者一消费者(操作值)
胶多不粘话多不甜,直接上代码: 生产者类: /** * Created by 51304 on 2016/2/28. */ public class P { private String lock; ...
- sql语句,多个表之间,通过相同内容字段的联合查询
1 , select j.id, jt.Name, j.ApproveType , j.ProductCode, j.CustomerCo ...
- 欢迎加入threejs
Threejs is the coolest graphics rendering engine I have ever seen, so what is threejs, Now, we have ...
- 转:mysql根据经纬度查找排序
一.MySql不使用空间函数,简单版 1.粗算,根据场景得到一个range,计算经纬度,得到的是一个矩形区域(A),不精确,但是已经有范围这个雏形了,最容易实现的方式之一. 1 2 3 4 5 6 w ...
- oracle查询某一个字段的数量总和
select count(*) from (select count(*) from 表名称 group by 多种数据量 ) 表名; 举个栗子: 比如说我有一个数据类型的字段, 里面有很多种的数据类 ...
- 【GoLang】golang 的精髓--流水线,对现实世界的完美模拟
直接上代码: package main import ( "fmt" "runtime" "strconv" "sync" ...