【Kmp求字符串前缀在字符串出现的次数】51nod 1277 字符串中的最大值
2017-07-24 20:03
288 查看
Link:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1277
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; /* 51nod 1277 字符串中的最大值 求前缀在字符串出现的次数 (num[i]) num[nex[i]] += num[i]; */ const int N = 100010; char s ; int nex ; void getnext(){ int len = strlen(s); int k = -1; nex[0] = -1; for(int i = 1; i < len; i++){ while(k!=-1 && s[k+1]!=s[i]) k = nex[k]; if(s[k+1]==s[i]) k++; nex[i] = k; } } int mp ; int main(){ scanf("%s",s); getnext(); int len = strlen(s); memset(mp,0,sizeof(mp)); for(int i = len; i >= 1; i--){ mp[i]++; mp[nex[i-1]+1] += mp[i]; // printf("%d %d \n",i,mp[i]); } LL mx = 0; for(int i = 1; i <= len; i++){ mx = max(mx,(LL)i*(LL)mp[i]); } printf("%lld\n",mx); return 0; }
相关文章推荐
- [KMP next树] 51Nod 1277 字符串中的最大值
- kmp-51nod 1277 字符串中的最大值
- 51Nod 1277 字符串中的最大值(KMP,裸题)
- 51NOD 1277 字符串中的最大值 【拓展KMP】
- 51nod 1277 字符串中的最大值 (kmp之next数组的理解) O(n)可过
- 51nod 1277 字符串中的最大值(kmp)
- 51nod 1277 字符串中的最大值(KMP)
- Zoj 3587 Marlon's String (KMP 字符串拼接 前缀出现次数)
- 51nod 1277 B - 字符串中的最大值 【KMP+dp】
- 字符串中的最大值 51Nod - 1277[DP+KMP]
- 【KMP next树】51nod 1277 字符串中的最大值
- 51nod-1277 字符串中的最大值(KMP)
- 1277 字符串中的最大值 (kmp)
- 字典树-大量字符串前缀及出现次数是否存在统计(Trie树-java)算法实现
- 给定一个字符串,统计一下哪个字符出现次数最大
- 51nod 1277 字符串中的最大值
- hdoj 4552 怪盗基德的挑战书 【KMP 求所有前缀在原串种出现的次数之和】
- 判断A字符串在B字符串中连续出现的最大次数
- String去除字符串两端空格、将一个字符串进行反转、计算字符串中出现的的次数、获取两个字符串中最大相同字串
- 用递归实现查找字符串中相同字符连续出现次数的最大值