HDU 6068 Classic Quotation KMP+DP】的更多相关文章

Classic Quotation Problem Description When online chatting, we can save what somebody said to form his ''Classic Quotation''. Little Q does this, too. What's more? He even changes the original words. Formally, we can assume what somebody said as a st…
/* HDU 6068 - Classic Quotation [ KMP,DP ] | 2017 Multi-University Training Contest 4 题意: 给出两个字符串 S[N], T[M], k个询问 每个询问给出 L,R 对所有 1<=i<=L , r<=j<=N , S串拿掉[i+1,j-1]的子串后,剩下两个子串拼在一起的子串中 T 串的数目求和 限制 N,k <= 5e4, M <= 100 分析: pre[i] 代表 前缀i匹配的T…
题 QAQ http://acm.hdu.edu.cn/showproblem.php?pid=6068 2017 Multi-University Training Contest - Team 4 - 1005 解 贴一张官方题解 其中S可以由O(n*m)的求前缀得到. 求suf贼难,淦. 求suf主要是通过类似DP的思想 其中ismatch[i][j]表示T的匹配指针为i,匹配到字母j的时候,是否新匹配了一个完整的T串. nxt2[i][j]表示,当T的匹配指针为i,匹配到字母j的时候,T…
题意 : 给出两个字符串,现在需要求一个和sum,考虑第二个字符串的所有后缀,每个后缀对于这个sum的贡献是这个后缀在第一个字符串出现的次数*后缀的长度,最后输出的答案应当是 sum % 1e9+7 分析 : 有两种做法,如果会拓展KMP的话可以说这就是一道模板题了,拓展KMP专门就是找最长公共前缀的长度,首先将给出的两个字符串双双反转,用模式串去跟主串跑一遍拓展KMP,得到 extend 数组,然后只要遍历一遍 extend 数组,每一个 extend[i] 表示模式串里面前 extend[i…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Another Meaning Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 As is known to all, in many cases, a word has two meanings. Such as "hehe", which not only…
题目链接 Problem Description When online chatting, we can save what somebody said to form his ''Classic Quotation''. Little Q does this, too. What's more? He even changes the original words. Formally, we can assume what somebody said as a string S whose…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4622 Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 2096    Accepted Submission(s): 715 Problem Description Now you are back,and…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意:给定两个字符串a和b,其中a中的字符串如果含有子串b,那么那部分可以被替换成*.问有多少种替换方法. kmp求出b在a中完全匹配后的结尾位置,然后dp(i)表示匹配到i时替换的方案数(不替换也算一次方案).首先更新dp(i)=dp(i-1),当且仅当i点是一个完全匹配的终点时,加上dp(i-nb)处的值. #include <bits/stdc++.h> using namespace…
HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义dp[i]表示以a[i]为结尾的子序列的和的最大值,因而最大连续子序列及为dp数组中的最大值.   状态转移方程:dp[1] = a[1]; //以a[1]为结尾的子序列只有a[1]:  i >= 2时, dp[i] = max( dp[i-1]+a[i],  a[i] ); dp[i-1]+a[i…
参考连接: KMP+DP: http://www.cnblogs.com/yuelingzhi/archive/2011/08/03/2126346.html 另外给出一个没用dp做的:http://blog.sina.com.cn/s/blog_82061db90100usxw.html 题意: 给出一个字符串,求它的各个前缀在字符串中出现的次数总和. 思路:记 dp[i] 为前 i 个字符组成的前缀出现的次数则 dp[next[i]]+=dp[i] dp[i]表示长度为i的前缀出现的次数,初…