JZOJ4387. 【GDOI2016模拟3.15】基因合成
来源:互联网 发布:网络广告制作软件 编辑:程序博客网 时间:2024/05/01 13:48
题目大意
一共有
- 将当前串翻转后接到原串中
- 在当前串首或串尾加入一个字符
Data Constraint
对于100%的数据:
题解
可以注意到操作中有一个翻转,每次操作完以后必然是一个回文串。可以发现目标串必然是由一个回文串(可能为空)再直接首尾添加字符得来。如果我们求出目标串中每一个回文串的最少操作次数,就可以得出答案了。这里可以用回文树来处理。
设
然后直接枚举选择某个回文串,求最小值就是答案。
SRC
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespace std ;#define N 100000 + 10struct Tree { int Son[4] ; int cost , len , fail ;} T[N] ;char S[N] ;int Tab[N] ;int Test , Last , L , tot , ans ;int Find( int now , int half ) { while ( T[now].len > half ) now = T[now].fail ; return now ;}int Getfail( int now ) { while ( S[L-T[now].len-1] != S[L] ) now = T[now].fail ; return now ;}void ADD( int c ) { L ++ ; int now = Getfail( Last ) ; if ( !T[now].Son[c] ) { T[++tot].fail = T[Getfail(T[now].fail)].Son[c] ; T[now].Son[c] = tot ; T[tot].len = T[now].len + 2 ; if ( (T[tot].len & 1) == 0 ) { int j = Find( T[tot].fail , T[tot].len / 2 ) ; T[tot].cost = min( T[now].cost + 1 , T[j].cost + T[tot].len / 2 - T[j].len + 1 ) ; } else T[tot].cost = T[tot].len ; } Last = T[now].Son[c] ;}int main() { freopen( "gene.in" , "r" , stdin ) ; freopen( "gene.out" , "w" , stdout ) ; scanf( "%d" , &Test ) ; Tab['A'] = 0 , Tab['C'] = 1 , Tab['G'] = 2 , Tab['T'] = 3 ; while ( Test -- ) { memset( T , 0 , sizeof(T) ) ; T[0].fail = T[0].cost = 1 ; T[1].len = -1 , T[1].cost = 2 ; Last = S[0] = 0 ; tot = 1 , L = 0 ; scanf( "%s" , S + 1 ) ; ans = strlen( S + 1 ) ; for (int i = 1 ; i <= ans ; i ++ ) ADD( Tab[S[i]] ) ; for (int i = 2 ; i <= tot ; i ++ ) ans = min( ans , T[i].cost + L - T[i].len ) ; printf( "%d\n" , ans ) ; } return 0 ;}
以上.
1 0
- JZOJ4387. 【GDOI2016模拟3.15】基因合成
- 【GDOI2016模拟3.15】染色
- 基因合成
- 合成基因的方式
- GDOI2016模拟8.10踢足球
- GDOI2016模拟8.8旋转
- GDOI2016模拟8.8处理器
- GDOI2016模拟8.13总结
- GDOI2016模拟8.14总结
- GDOI2016模拟8.14数树数
- GDOI2016模拟8.15总结
- GDOI2016模拟8.15蜘蛛侠
- GDOI2016模拟8.15送票
- GDOI2016模拟8.16总结
- GDOI2016模拟8.16帮派
- GDOI2016模拟8.18总结
- GDOI2016模拟8.18蜡笔
- GDOI2016模拟8.18的士
- listView的使用之例如QQ消息列表
- 一些常用到的自定义宏
- Swift类和结构体详解
- 解决_CRT_SECURE_NO_WARNINGS 警告
- 为你的android App实现自签名的ssl证书(https)
- JZOJ4387. 【GDOI2016模拟3.15】基因合成
- 去掉tableView中多余的分割线
- 各种数据库的分页查询语句
- 世纪佳缘财务及运营数据分析
- humb变小点
- python中range()与xrange()区分
- 北邮OJ 1005. 16校赛-Hawei Learning C
- 粗糙的SEM点击率分析模型
- Redis Master/Salve Replication(主从复制模式)