hdu3689(kmp+dp)】的更多相关文章

题意:问随机生成一个长度为m(m<=1000)长度的字符串,出现某个子串s的概率是多少. 解法:dp+kmp优化.ans[i][j]表示i长度,走到了s的j位置的概率,当然这是在i之前没有出现s的前提下(在状态转移时候已经保证了这一点):然后最后的概率就是1-m长度的串分别最后出现s的概率之和. 代码: /****************************************************** * @author:xiefubao **********************…
2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP) https://www.luogu.com.cn/problem/P3426 题意: 你打算在纸上印一串字母. 为了完成这项工作,你决定刻一个印章.印章每使用一次,就会将印章上的所有字母印到纸上. 同一个位置的相同字符可以印多次.例如:用 aba 这个印章可以完成印制 ababa 的工作(中间的 a 被印了两次).但是,因为印上去的东西不能被抹掉,在同一位置上印不同字符是不允许的.例如:用 aba 这个…
题目链接: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…
题目链接 题意:求给定字符串中,可以与某一前缀相同的所有子串的数量 做这道题需要明白KMP算法里next[]数组的意义 首先用一数组nex[](这里与之前博客中提到的next明显不同)存储前缀后缀最长公共元素长度.(nex[i]表示,在S[1~i](在标号从1开始的情况下)这个字串中,前缀后缀最长公共元素长度) 然后使用一数组dp[],dp[x]中存放 S[1~x]中共含有 以S[x]结尾的&&与某一字串相同 字串的个数 这样递推一下,然后把所有dp[i]求个和就是ans了 #includ…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5763 思路:dp[i]表示前i个字符组成的字符串所表示的意思数量,则当匹配时dp[i]=dp[i-1]+dp[i-lenb],不匹配时dp[i]=dp[i-1].匹配的判断可以用KMP. #include<cstdio> #include<cstring> using namespace std; typedef long long ll; const int N=1e5+3; con…
题意: 求给定字符串,包含的其前缀的数量. 分析: 就是求所有前缀在字符串出现的次数的和,可以用KMP的性质,以j结尾的串包含的串的数量,就是next[j]结尾串包含前缀的数量再加上自身是前缀,dp[i]表示以i为结尾包含前缀的数量,则dp[i]=dp[next[i]]+1,最后求和即可. #include <map> #include <set> #include <list> #include <cmath> #include <queue>…
Another Meaning 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Description As is known to all, in many cases, a word has two meanings. Such as "hehe", which not only means "hehe", but also means "excuse me". Today, ?? i…
Problem Description It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example: s: "abab" The prefixes are: "…
题目链接 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…
Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6875    Accepted Submission(s): 3191 Problem Description It is well known that AekdyCoin is good at string problems as well as nu…