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. 使用python书写的小说爬虫

    1.写了一个简单的网络爬虫 初期1 (后期将会继续完善) #小说的爬取 import requests import random from bs4 import BeautifulSoup base ...

  2. RGB颜色空间、色调、饱和度、亮度,HSV颜色空间详解

    本文章会详细的介绍RGB颜色空间与RGB三色中色调.饱和度.亮度之间的关系,最后会介绍HSV颜色空间! RGB颜色空间 概述 RGB颜色空间以R(Red:红).G(Green:绿).B(Blue:蓝) ...

  3. axios token header response request http拦截器 axios实现登录、拦截、登出

    axios token header response request http拦截器 axios实现登录.拦截.登出 一个项目学会前端实现登录拦截 https://github.com/superm ...

  4. 把特征网络换成resnet-50

    从RFCN来看,Resnet-50和Resnet-101到最后一层卷积都是缩小到原来尺寸的16分之一,并且都用的7x7的格子去roi pooling. 看paper可以知道:resnet-50核心是由 ...

  5. treeTable的使用(ajax异步获取数据,动态渲染treeTable)

    一.展示效果(treetable基本样式https://www.cnblogs.com/shuihanxiao/p/10413454.html) 二.html文件(若一个页面又多个treetable, ...

  6. Sql Server 中锁的概念(1)

    Sql Server 中锁的概念   锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破 ...

  7. xshell全局设置配色方案

    新建XTerm1.xcs文件,将以下内容黏贴进去,保存退出 [XTerm] text=839496 cyan(bold)=93a1a1 text(bold)=408080 magenta=dd3682 ...

  8. 清除SQL Server 2008记住的数据库地址、登录名和密码

    在服务器上登录过数据库信息,并且选择了记住了密码,由于服务器数据库很多人在使用,有必要删除信息 定位到fileC:\Users\%username%\AppData\Roaming\Microsoft ...

  9. mysql在线开启或禁用GTID模式

    在线开启步骤: 1.要求: (1)必须是5.7.6版本以上的mysql (2)GTID状态为OFF 2.开启步骤: (1):SET GLOBAL ENFORCE_GTID_CONSISTENCY = ...

  10. fit in gnuplot

    Table of Contents 1. fit-gnuplot 1 fit-gnuplot syntax >> fit [xrange][yrange] function 'datafi ...