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 ...
随机推荐
- Inno Setup入门(九)——修改安装过程中的文字显示
前面说到过可以使用不用的语言文件实现不同的显示方式,方便与国际接轨,事实上即使没有语言文件也可以实现修改.[Messages]段用于定义安装程序和卸载程序中显示的消息.一般不需要创建 [Message ...
- 倒计时demo
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong,nonatom ...
- protobuf使用NDK编译Android的静态库(工作记录)
1.protobuf 编译过程 前提: 确保自己电脑上已经安装了cygwin + ndk, 并且NDK能够编译hello-jni成功 1.1 把protobuf 压缩包解压到protobuf文件夹下 ...
- 封装sdk API 应用
1 #include "QWinApp.h" 2 #include "QGlobal.h" 3 int WINAPI _tWinMain(HINSTANCE h ...
- java应用测试报告生成(二):利用ant的build.xml生成测试报告
1.将写好的项目导出 在工程下会生成一个build.xml的蚂蚁图标的文件. 2.右击该文件,选择run as Ant build 其中的测试目录是可以选择的,如果涉及到顺序也可以调整顺序 3.执行后 ...
- ios 获得版本号
获取iphone的系统信息使用[UIDevice currentDevice],信息如下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS ...
- Light OJ 1008
找规律. 首先令n=sqrt(s),上取整.讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的. Sam ...
- Image File Execution Options(转)
今天公司的一台计算机无法正常工作送来维修,经简单判断是感染了很多病毒,即使在安全模式下也无法清除:于是将硬盘摘下挂到另外一台机器上,用卡巴斯基对病毒进行了查杀,再次启动计算机后发现很多系统维护程序以及 ...
- SpringMVC中获得HttpRequest对象的方法
1. 使用@autowired注入HttpRequest 2. 在方法中直接声明形参有HttpRequest即可. 3. 使用一个Listener,然后获取.
- chromium blog
http://blog.chromium.org/