[HDU5677]ztr loves substring
ztr loves substring
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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".
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<cstdio>
- #include<cstring>
- using namespace std;
- const int N=;
- int n,t,m,k,ct,mx,l;
- int r[N<<],f[N][N],vis[N];
- char s[N<<],str[N];
- inline int max(int a,int b){return a>b?a:b;}
- inline int min(int a,int b){return a<b?a:b;}
- inline void manacher()
- {
- memset(s,,sizeof(s));
- n=;m=strlen(str);
- s[n++]=;s[n++]=;
- for(int i=;i<m;i++)s[n++]=str[i],s[n++]=;
- memset(r,,sizeof(r));ct=mx=;
- for(int i=;i<n;i++)
- {
- if(i<mx)r[i]=min(mx-i,r[*ct-i]);
- else r[i]=;
- while(<=i-r[i]&&i+r[i]<n&&s[i-r[i]]==s[i+r[i]])r[i]++;
- if(i+r[i]>mx)ct=i,mx=i+r[i];
- int j=r[i]-;
- while(j>=)vis[j]++,j-=;
- }
- }
- int c[N*N],v[N*N],cnt;
- inline bool backpack()
- {
- memset(f,,sizeof(f));
- for(int i=;i<=l;i++)
- {
- int tmp=;
- while(vis[i]>=tmp)
- c[++cnt]=tmp*i,v[cnt]=tmp,vis[i]-=tmp,tmp<<=;
- if(vis[i])
- c[++cnt]=vis[i]*i,v[cnt]=vis[i];
- }
- f[][]=;
- for(int u=;u<=cnt;u++)
- for(int i=l;i>=c[u];i--)
- for(int j=k;j>=v[u];j--)
- f[i][j]|=f[i-c[u]][j-v[u]];
- return f[l][k];
- }
- int main()
- {
- int cnt;scanf("%d",&cnt);
- while(cnt--)
- {
- scanf("%d%d%d",&t,&k,&l);
- memset(vis,,sizeof(vis));
- for(int i=;i<=t;i++)
- scanf("%s",str),manacher();
- if(backpack())printf("True\n");
- else printf("False\n");
- }
- }
HDU5677
[HDU5677]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( ...
- HDU 5677 ztr loves substring
Manacher+二维费用多重背包 二进制优化 这题是一眼标算....先计算出每个长度的回文串有几种,然后用二维费用的多重背包判断是否有解. 多重背包做的时候需要二进制优化. #include< ...
- 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 ...
随机推荐
- cdh中hdfs非ha环境迁移Namenode与secondaryNamenode,从uc机器到阿里;
1.停掉外部接入服务: 2 NameNode Metadata备份: 2.1 备份fsimage数据,(该操作适用HA和非HA的NameNode),使用如下命令进行备份: [root@cdh01 df ...
- Yii 2.0 使用片段缓存
网站首页footer中的菜单标题是从数据库读取并显示处理的. 也就是 <footer>标题里面是foreach.这样每个人打开网站就查询遍历效率会很低. <footer class= ...
- 八月暑期福利,10本Python热门书籍免费送!
八月第一周,网易云社区联合博文视点为大家带来Python专场送书福利,10本关于Python的书籍内容涉及Python入门.绝技.开发.数据分析.深度学习.量化投资等.以下为书籍简介,送书福利请见文末 ...
- LUA中点号和冒号的区别
Student = {}; Student.__index = Student; function Student:new(name, age) local temp = {}; setmetatab ...
- 三、利用EnterpriseFrameWork快速开发Winform系统(C/S)
EnterpriseFrameWork框架实例源代码下载: 实例下载 上一章讲解了开发Web系统的详细步骤,以书籍的管理作实例实现对书籍的增.删.改.查功能,本章接着上面的实例继续补充用Winform ...
- python练习---小脚本
一.爬子域名 #!/usr/bin/python # -*- coding: utf-8 -*- import requests import re import sys def get(domain ...
- JMeter:全面的乱码解决方案【转】
本文是转自https://www.cnblogs.com/mawenqiangios/p/7918583.html 感谢分享者 中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中, ...
- Unity中StopCoroutine不起作用怎么办
1,只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine(string CoroutineName)停用. 2, public Coroutine coroutine ...
- leetcode-优美的排列
假设有从 1 到 N 的 N 个整数,如果从这 N 个数字中成功构造出一个数组,使得数组的第 i 位 (1 <= i <= N) 满足如下两个条件中的一个,我们就称这个数组为一个优美的排列 ...
- MVC与ajax【转】
首先我们要实现用户的注册功能.进入visual studio 点击文件->新建->项目->选择ASP.NET Web应用程序(.NET Framework)->选择的模板为MV ...