[jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)
题目链接:
https://jzoj.net/senior/#main/show/5178
题目:

题解:
我们定义$f[pos]$表示以位置pos为后缀的字符串对答案的贡献,答案就是$\sum_{i=1}^{n} f[i]$
考虑怎么得到f数组,我们有$f[i]=f[nxt[i]]+[i是偶数]$
其实蛮显然的,$f[i]$和$f[nxt[i]]$除了多出前缀i这个贡献没什么区别
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll; const int N=2e5+;
char ch[N];
int nxt[N],f[N];
int main()
{
scanf("%s",ch+);
nxt[]=;
int n=strlen(ch+);
for (int i=,j=;i<=n;i++)
{
while (j&&ch[j+]!=ch[i]) j=nxt[j];
if (ch[j+]==ch[i]) ++j;
nxt[i]=j;
}
for (int i=;i<=n;i++)
{
if (!(i&)) f[i]=f[nxt[i]]+;
else f[i]=f[nxt[i]];
}
ll ans=;
for (int i=;i<=n;i++) ans+=f[i];
printf("%d\n",ans);
return ;
}
[jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)的更多相关文章
- [jzoj 5177] [NOIP2017提高组模拟6.28] TRAVEL 解题报告 (二分)
题目链接: https://jzoj.net/senior/#main/show/5177 题目: 题解: 首先选出的泡泡怪一定是连续的一段 L,R 然后 L 一定属于虫洞左边界中的某一个 R 也同样 ...
- [JZOJ5178]【NOIP2017提高组模拟6.28】So many prefix?
Description
- JZOJ 5184. 【NOIP2017提高组模拟6.29】Gift
5184. [NOIP2017提高组模拟6.29]Gift (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Detailed ...
- JZOJ 5196. 【NOIP2017提高组模拟7.3】B
5196. [NOIP2017提高组模拟7.3]B Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5197. 【NOIP2017提高组模拟7.3】C
5197. [NOIP2017提高组模拟7.3]C Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5195. 【NOIP2017提高组模拟7.3】A
5195. [NOIP2017提高组模拟7.3]A Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence
5185. [NOIP2017提高组模拟6.30]tty's sequence (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB ...
- NOIP2017提高组 模拟赛15(总结)
NOIP2017提高组 模拟赛15(总结) 第一题 讨厌整除的小明 [题目描述] 小明作为一个数学迷,总会出于数字的一些性质喜欢上某个数字,然而当他喜欢数字k的时候,却十分讨厌那些能够整除k而比k小的 ...
- NOIP2017提高组 模拟赛13(总结)
NOIP2017提高组 模拟赛13(总结) 第一题 函数 [题目描述] [输入格式] 三个整数. 1≤t<10^9+7,2≤l≤r≤5*10^6 [输出格式] 一个整数. [输出样例] 2 2 ...
随机推荐
- 51nod-1363: 最小公倍数之和
[传送门:51nod-1363] 简要题意: 给出一个数n,求出1到n的数与n的最小公倍数的和 多组数据 题解: 理所当然推柿子 原题相当于求$\sum_{i=1}^{n}\frac{i*n}{gcd ...
- ROS-SLAM-自主导航
前言:无. 前提:已下载并编译了相关功能包集,如还未下载,可通过git下载:https://github.com/huchunxu/ros_exploring.git 一.启动仿真环境 cd ~/ca ...
- Javascript 正则表达式简述
本文地址:http://www.cnblogs.com/blackmanba/p/regular-expressions-introduce.html 或者 http://forkme.info/re ...
- Win8 Windows Defender default behaviour
Problem Description ********************* Is it possible, to change the default behaviour when findi ...
- java根据出生日期计算年龄
/** * @author jerry.chen * @param brithday * @return * @throws ParseException * 根据生日获取年龄; */ public ...
- hdu 1394 Minimum Inversion Number 【线段树求逆序数】
之前写过树状数组的,再用线段树写一下--- #include<cstdio> #include<cstring> #include<iostream> #inclu ...
- 脚本_统计每个远程IP访问本机apache的次数
#!bin/bash#功能:统计每个远程IP访问本机apache的次数#作者:liusingbonawk '{ip[$1]++} END{for(i in ip){print ip[i],i}}' ...
- 洛谷T44252 线索_分治线段树_思维题
分治线段树,其实就是将标记永久化,到最后再统一下传所有标记. 至于先后顺序,可以给每个节点开一个时间戳. 一般地,分治线段树用于离线,只查询一次答案的题目. 本题中,标记要被下传 222 次. Cod ...
- 路飞学城Python-Day39(第四模块复习题)
并发编程 一.简答题 1,简述计算机操作系统的中断的作用 由于cpu本身一次只能执行一个程序,操作系统提供的中断机制使得cpu能够实现不断的在各个程序间进行切换,给人的感觉就是多个程序同时执行 为什么 ...
- ajax中遇到无法发送的问题,以及收不到返回信息的问题
1.在做ajax时,数据发送成功,后台确认了也返回了信息,但是怎么都在success里面接收不了,我遇见的造成的原因时因为dataType返回值类型错误造成的原因. var url = "请 ...