HDU 5677 ztr loves substring
Manacher+二维费用多重背包 二进制优化
这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解。
多重背包做的时候需要二进制优化。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = ;
int N, p[maxn];
char str[maxn], b[maxn];
int cnt[maxn];
int n, k, L;
bool dp[maxn][maxn]; void init()
{
int i;
for (i = ; str[i]; i++) b[ * i + ] = '#', b[ * i + ] = str[i];
N = * i + ;
b[] = '$', b[N] = b[N + ] = '#';
} void solve()
{
int i, id, max = ;
for (i = ; i <= N; i++)
{
p[i] = i < max ? std::min(max - i, p[ * id - i]) : ;
while (b[i + p[i]] == b[i - p[i]]) ++p[i];
if (i + p[i] > max) max = i + p[i], id = i;
cnt[p[i] - ]++;
}
}
int main()
{
int T; scanf("%d", &T);
while (T--)
{
memset(dp, , sizeof dp); dp[][] = ;
memset(cnt, , sizeof cnt);
scanf("%d%d%d", &n, &k, &L);
while (n--){ scanf("%s", str); init(); solve(); }
for (int i = ; i >= ; i--)
cnt[i] = cnt[i] + cnt[i + ];
for (int i = ; i >= ; i--)
{
if (cnt[i] == ) continue;
int val = i, num = cnt[i];
int t = ;
while (num)
{
if (num > t)
{
int tmp_val = val*t;
for (int d = L; d >= ; d--)
{
for (int f = k; f >= ; f--)
{
if (dp[d][f] == ) continue;
if (d + tmp_val <= L&&f + t <= k)
dp[d + tmp_val][f + t] = ;
}
}
num = num - t;
t = t * ;
}
else
{
int tmp_val = val*num;
for (int d = L; d >= ; d--)
{
for (int f = k; f >= ; f--)
{
if (dp[d][f] == ) continue;
if (d + tmp_val <= L&&f + num <= k)
dp[d + tmp_val][f + num] = ;
}
}
num = ;
}
}
}
if (dp[L][k]) printf("True\n");
else printf("False\n");
}
return ;
}
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 多重背包
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...
- [HDU5677]ztr loves substring
ztr loves substring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 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 ...
随机推荐
- poi 合并单元格、设置边框
HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); //创建一个样式 HSSFCellStyle sty ...
- OpenGL------在Windows系统中显示文字
增加了两个文件,showline.c, showtext.c.分别为第二个和第三个示例程序的main函数相关部分.在ctbuf.h和textarea.h最开头部分增加了一句#include <s ...
- 栅栏cyclicbarrier
栅栏类似闭锁,但是它们是有区别的. 1.闭锁用来等待事件,而栅栏用于等待其他线程.什么意思呢?就是说闭锁用来等待的事件就是countDown事件,只有该countDown事件执行后所有之前在等待的线程 ...
- AndroidStudio使用注意事项
今天在引入GitHUb上的开源框架时,写好依赖后编译时,报以下错误: Error:Execution failed for task ':app:processDebugResources'.> ...
- 在线的代码托管平台 coding.net ===中国扩展版github
coding.net 是国内新兴的一个项目管理平台,功能主要包括:代码托管.在线运行环境.监控代码质量,兼有一定的社交功能. 在线运行环境支持Java.Ruby.Node.js.PHP.Python. ...
- Opencv 图像叠加 添加水印
Opencv 图像叠加 添加水印 C++: void Mat::copyTo(OutputArray m) const C++: void Mat::copyTo(OutputArray m, Inp ...
- MVC 创建Word文档
/// <summary> /// 创建一个word /// </summary> /// <returns></returns> public Act ...
- hdu_3549_Flow Problem(最大流)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 题意:求1到n的最大流 题解:模版题,直接上Claris的ISAP,效率是一般dfs的十倍,OR ...
- 以前的loginUI
的 <%@ page language="java" pageEncoding="UTF-8"%> <%@ include file=&quo ...
- Fragment和Activity(转)
Android Fragment和Activity Fragment和Activity Fragment和Activity的交互 一个Fragment的实例总是和包含它的Activity直接相关. f ...