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 ...
随机推荐
- go for range 可以方便的对slice 切片或者 map 进行迭代循环
package main import ( "fmt" "math/rand" "time" ) func main ...
- ASP.NET Core分布式项目-1.IdentityServer4登录中心
源码下载 一.添加服务端的api 1.添加NUGet包 IdentityServer4 点击下载,重新生成 2.添加Startup配置 打开Startup文件 public class Startup ...
- Nginx学习笔记(三):Nginx 请求处理
Request Nginx 中的 ngx_http_request_t 是对一个 http 请求的封装: 一个 http 请求包含:请求行.请求头.请求体,响应行.响应头.响应体 Nginx 处理请求 ...
- Thrift RPC Golang、C++ Example
Thrift RPC Example 运行 请直接使用即可,无需拉取任何依赖包. cd $GOPATH/src git clone https://github.com/hunterhug/thrif ...
- SQL 遍历删除所有表的数据
https://www.cnblogs.com/yige/p/5193253.html declare @sqlTabName varchar(100);-- 声明游标DECLARE C_Employ ...
- python实现暴力破解
import urllib2 import urllib import cookielib import threading import sys import Queue from HTMLPars ...
- 关于一个mvc架构的cms的后台getshell
都知道,mvc的话 除了根目录还有public目录可以访问,其他的访问都是不行的,因为会默认都是会解析url 然后我们来看今天的猪脚 大概的图片上传还有远程文件加载我黑盒测过了 就是想捞一个快一点的 ...
- ntp时间同步简介
网络时间协议(Network Time Protocol) 安装 # sudo apt-get install ntp 官网下载:http://www.ntp.org/downloads.html 本 ...
- JAVA基于PDF box将PDF转为图片
在一项目中用到,本身我是.NET的,团队中有用到JAVA,故此我处理这个功能,记录以下备用. 1.引用:fontbox-2.0.16.jar.pdfbox-app-2.0.16.jar 版本一定要正确 ...
- 【翻译】--19C Oracle 安装指导
18C新功能 1.简化的基于镜像的Oracle数据库安装 从18C开始,Oracle可以作为镜像文件来下载和安装,必须解压缩镜像文件到ORACLE_HOME目录,然后执行runInst ...