CF557E Ann and Half-Palindrome 字典树+dp
现在看这道题也不难啊,不知道考场上为啥没切~
code:
#include <bits/stdc++.h>
#define N 5006
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct trie
{
int size,tag,ch[2];
}p[N*2500];
char S[N];
int f[N][N],tot;
void dfs(int u)
{
p[u].size=p[u].tag;
for(int i=0;i<2;++i)
{
if(p[u].ch[i])
{
int v=p[u].ch[i];
dfs(v);
p[u].size+=p[v].size;
}
}
}
void dfs2(int u,int kth)
{
kth-=p[u].tag;
if(kth<=0)
{
exit(0);
}
for(int i=0;i<2;++i)
{
if(p[u].ch[i])
{
int v=p[u].ch[i];
if(kth>p[v].size) kth-=p[v].size;
else {
printf("%c",i+'a');
dfs2(v, kth);
break;
}
}
}
}
int main()
{
int i,j,n,k,rt=0;
// setIO("input");
scanf("%s%d",S+1,&k);
n=strlen(S+1);
for(i=1;i<=n;++i) f[i][i]=1;
for(i=n-1;i>=1;--i)
{
for(j=i+1;j<=n;++j)
{
if(j-2>=i+2)
{
if(S[i]==S[j] && f[i+2][j-2]) f[i][j]=1;
}
else
{
if(S[i]==S[j]) f[i][j]=1;
}
}
}
for(i=1;i<=n;++i)
{
rt=0;
for(j=i;j<=n;++j)
{
int c=S[j]-'a';
if(!p[rt].ch[c])
{
p[rt].ch[c]=++tot;
}
rt=p[rt].ch[c];
p[rt].tag+=f[i][j];
}
}
dfs(0);
dfs2(0,k);
return 0;
}
CF557E Ann and Half-Palindrome 字典树+dp的更多相关文章
- Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)
E. Ann and Half-Palindrome time limit per test 1.5 seconds memory limit per test 512 megabytes input ...
- Manthan, Codefest 16 C. Spy Syndrome 2 字典树 + dp
C. Spy Syndrome 2 题目连接: http://www.codeforces.com/contest/633/problem/C Description After observing ...
- UVALive 3942 Remember the Word 字典树+dp
/** 题目:UVALive 3942 Remember the Word 链接:https://vjudge.net/problem/UVALive-3942 题意:给定一个字符串(长度最多3e5) ...
- LA 3942 - Remember the Word (字典树 + dp)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- HDU5715 XOR 游戏 二分+字典树+dp
当时Astar复赛的时候只做出1题,赛后补题(很长时间后才补,懒真是要命),发现这是第二简单的 分析: 这个题,可以每次二分区间的最小异或和 进行check的时候用dp进行判断,dp[i][j]代表前 ...
- BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)
<题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...
- UVALive 3942 字典树+dp
其实主要是想学一下字典树的写法,但这个题目又涉及到了DP:这个题目要求某些单词组成一个长子串的各种组合总数,数据量大,单纯枚举复杂度高,首先肯定是要把各个单词给建成字典树,但是之后该怎么推一时没想到. ...
- CF456D A Lot of Games (字典树+DP)
D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...
- LA 3942 - Remember the Word 字典树+DP
看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
随机推荐
- 针对Quizii的基本抓包实验(Fiddler)
本实验仅限于了解POST和GET几种常规数据获取方案的学习.简单的来说,POST就是向服务器发送数据,GET会向服务器请求数据.可以参考https://www.zhihu.com/question/2 ...
- (五)Hibernate的增删改查操作(2)
接上一章节 HQL的预编译语句 HIbernate中的预编译与Spring的预编译的处理差不多. 1:使用标准的? 2:使用命名参数 2.1:使用名称逐个设置. 2.2:使用Map(k ...
- (七)mybatis之多对一关系(复杂)
一.需求分析 需求:查询所有消费者信息,关联查询订单及商品信息,订单明细信息中关联查询查商品信息. 分析:一个消费者有多条订单,一条订单只有一个消费者但是有多条订单明细,一条订单明细只有一个商品信息. ...
- Java CountingSort
Java CountingSort /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternation ...
- powerdesign中逆向工程后name和comment的互换
powerdesign 中,将数据库中可以逆向生成pdm的结构图,比较清晰看到系统的结构, 但假如是db先行的话,一般是db中的每个列中用comment中文注释说明这列是 干什么的,但逆向工程后,会发 ...
- Xamarin开发综述
https://blog.csdn.net/qq_41647999/article/details/84844357 一. 前言这十来天对Xamarin的学习踩了很多的坑,说来也是一把心酸泪,下面为大 ...
- centos 随机启动脚本编写
先说下问题背景 目前手上开发的产品是springboot微服务的,我们用jenkins来做的部署,部署脚本如下: 1.build脚本 负责从git服务器拉脚本 2.微服务脚本: #!/bin/shap ...
- web服务器端挖矿代码攻击的错误检测及排除
a)挖矿代码简要阐述: 网页中嵌入Javascript, 一旦用户打开该网站,浏览器便会按照脚本的指令变成一个门罗币挖矿机.这一段附加的挖矿代码通常因为大量占用CPU,使用户的计算机变得异常卡顿甚至无 ...
- Array + two points leetcode.16 - 3Sum Closest
题面 Given an array nums of n integers and an integer target, find three integers in nums such that th ...
- Linux——CentOS7安装gcc编译器详解 查看内核版本
[root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:3 ...