11:

KMP next 的强大

题意求前缀在S中出现的次数之和

next[j] 表示 S[0....NEXT[J]]==S[J-NEXT[J].....J];

于是我们得到。。后加入一个字符所得到新的前缀会多ADD[next[J]]个

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define N 123456
char s[N];
int next[N];
int n;
ll a[N];
void kmp()
{
    n=strlen(s);
    int i=0,j=-1;
    next[0]=-1;
    while (i<n)
    {
        if (j==-1||s[i]==s[j])
        {
            i++;
            j++;
            next[i]=j;
        }else j=next[j];
    }
}
int main()
{
    while (scanf("%s",s)!=EOF)
    {
        kmp();
        ll ans=0;
        memset(a,0,sizeof(a));
        for (int i=1;i<=n;i++)
        {
            a[i]=a[next[i]];
            a[i]++;
            ans+=a[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}

HUST 1328 String的更多相关文章

  1. HUST 1328 String (字符串前缀子串个数 --- KMP)

    题意 给定一个字符串S,定义子串subS[i] = S[0..i],定义C[i]为S中subS[i]的数量,求sigma(C[i])(0<=i<N). 思路 我们以子串结尾的位置来划分阶段 ...

  2. HUST 4681 String (DP LCS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 题目大意:给定三个字符串A,B,C 求最长的串D,要求(1)D是A的字序列 (2)D是B的子序列 ...

  3. string黑科技

    1. string对象的定义和初始化以及读写 string s1; 默认构造函数,s1为空串string s2(s1); 将s2初始化为s1的一个副本string s3("valuee&qu ...

  4. poj 1328 Radar Installation

    题目链接:http://poj.org/problem?id=1328 题意:给出海上有n个小岛的坐标,求发出的信号可以覆盖全部小岛的最少的雷达个数.雷达发射信号是以雷达为圆心,d为半径的圆,雷达都在 ...

  5. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  6. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  7. 字符串 - 近似回文词 --- csu 1328

    近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...

  8. AC自动机---Searching the String

    ZOJ   3228 题目网址:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16401 Description Little ...

  9. KMP---Count the string

    题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110060#problem/A Description It is well k ...

随机推荐

  1. 【HEVC帧间预测论文】P1.2 An Efficient Inter Mode Decision Approach for H.264 Video Codin

    参考:An Efficient Inter Mode Decision Approach for H.264 Video Coding <HEVC标准介绍.HEVC帧间预测论文笔记>系列博 ...

  2. ElasticSearch的常用方法

    关键词  cluster  集群  shards  索引分片    replicas  索引的副本    recovery  数据重新分布 gateway  索引的持久化方式 Transport 交互 ...

  3. tensorflow-gpu install check

    https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c#file-tensorflow_self_check-py-L16

  4. 工作流activi链接地址

    http://topmanopensource.iteye.com/blog/1313865

  5. 剑指Offer整理笔记

    说在前面,本篇的目的是为了学习剑指offer,以及博客园的排版功能,并将文章排版得整洁得体. 梵蒂冈梵蒂冈地方官方

  6. bzoj 1098 [POI2007] 办公楼 biu

    # 解题思路 画画图可以发现,只要是两个点之间没有相互连边,那么就必须将这两个人安排到同一个办公楼内,如图所示: 那,我们可以建立补图,就是先建一张完全图,然后把题目中给出的边都删掉,这就是一张补图, ...

  7. minGW64编译Qt

    1.安装minGW64,设置bin目录到环境变量Path 2.cmd 到qt的Src目录 3.configure -debug-and-release -opensource -prefix &quo ...

  8. mysql查询表中最小可用id值

    今天在看实验室的项目时,碰到的一个问题,.先把sql语句扔出来 // 这条语句在id没有1时,不能得到正确的查询结果. select min(id+1) from oslist c where not ...

  9. 树莓派搭建Seafile个人网盘

    步骤一.安装Seafile依赖包 yum install python-setuptools python-ldap python-memcached MySQL-python mariadb mar ...

  10. 在docker中部署nginx

    1端口映射 大写P  为容器暴漏的所有端口进行映射   -p ,--publish-all=true    docker run -P -it centos  /bin/bash 小写p  指定哪些容 ...