HDU 5763 Another Meaning (kmp + dp)】的更多相关文章

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…
题目链接: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…
题目链接: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…
2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP) https://www.luogu.com.cn/problem/P3426 题意: 你打算在纸上印一串字母. 为了完成这项工作,你决定刻一个印章.印章每使用一次,就会将印章上的所有字母印到纸上. 同一个位置的相同字符可以印多次.例如:用 aba 这个印章可以完成印制 ababa 的工作(中间的 a 被印了两次).但是,因为印上去的东西不能被抹掉,在同一位置上印不同字符是不允许的.例如:用 aba 这个…
http://acm.split.hdu.edu.cn/showproblem.php?pid=4035 Maze Special Judge Problem Description   When wake up, lxhgww find himself in a huge maze. The maze consisted by N rooms and tunnels connecting these rooms. Each pair of rooms is connected by one a…
题意:我们定义每一位先严格递增(第一位不为0)后严格递减的数为峰(比如1231),一个数由两个峰组成称为双峰,一个双峰的价值为每一位位数和,问L~R双峰最大价值 思路:数位DP.显然这个问题和pos有关,和前一项有关,和当前状态有关,我们定义dp[i][j][k]第i位前面j状态k的后面的最佳情况. 状态有7种: 0什么都没,1刚开始第一个上坡,2已经第一个上坡了可以转折了,3第一个下坡04刚开始第二个上坡,5已经第二个上坡可以转折了,6第二个下坡 然后数位DP一下就好了. 注意,要开ull,3…
Problem Description While studying the history of royal families, you want to know how wealthy each family is. While you have various 'net worth' figures for each individual throughout history, this is complicated by double counting caused by inherit…
http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意: 给出一个字符串和一个模式串,模式串有两种意思,问这句话有几种意思. 思路:因为肯定要去字符串去找模式串,所以首先用KMP计算next数组,然后用动态规划,d[i]表示分析到第i个字符时有多少种意思. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #inclu…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解] 我们定义数组f为S串中T出现的最后一个字母所在的位置,那么ans[i]=ans[i-1]+f[i-1]?ans[i-lenT]:0,一遍递推即可,所以关键就在于求出f数组了,f数组可以用kmp求,由于最近练FFT,用FFT求距离卷积匹配为0的位置,就是f数组了. [代码] #include <c…
题意: 求给定字符串,包含的其前缀的数量. 分析: 就是求所有前缀在字符串出现的次数的和,可以用KMP的性质,以j结尾的串包含的串的数量,就是next[j]结尾串包含前缀的数量再加上自身是前缀,dp[i]表示以i为结尾包含前缀的数量,则dp[i]=dp[next[i]]+1,最后求和即可. #include <map> #include <set> #include <list> #include <cmath> #include <queue>…