落谷P3041 [USACO12JAN]Video Game G】的更多相关文章

题目链接 多模式匹配问题,先建 AC 自动机. 套路性的搞个 DP: \(f[i][j]\) 表示前 \(i\) 个字符,当前在 \(AC\) 自动机上的节点是 \(j\) 能匹配到的最多分. 初始化 \(f[0][0] = 0\),其余为负无穷 答案 \(\max\{f[K][i]\}\) 考虑一条边 \(u \Rightarrow v\),加入后缀的贡献,即 \(f[i][v] = \max(f[i - 1][u] + val(v))\) 其中 \(val(v)\) 表示 \(v\) 这个点…
题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only valid buttons. Bessie may press the buttons in any order she likes; however, there are only N distinct combos possible (1 <= N <= 20). Combo i is repr…
第一道\(AC\)自动机\(+DP.\) 首先,一个自动机上\(DP\)的套路是设\(dp[i][j]\)表示长度为\(i\)匹配到\(j\)节点的最优得分. 那么,由于我们已经建好了\(Trie\)图,我们就应该提前把走到节点\(j\)的所有连击操作处理出来. 有一条显然结论:如果在\(fail\)树上经过了这个串结尾节点中子树中的任意一点,则这次匹配一定会包含这个串. 换句话说,我们在对每一个节点更新\(fail\)的时候,其分值应该直接把其\(fail\)的分值加上. 于是我们进行\(dp…
正解:AC自动机+dp 解题报告: 传送门! 算是个比较套路的AC自动机+dp趴,,, 显然就普普通通地设状态,普普通通地转移,大概就f[i][j]:长度为i匹配到j 唯一注意的是,要加上所有子串的贡献,就在结构体中新加一个变量d表示在跟到这个节点的串以及后缀中完整串的个数 直接在bfs求fail的时候加上fail指针的d就欧克 啊当然只是为了方便描述所以说另开一个d,,,实际实现的话直接把标记结尾的那个值改成int类型搞下就欧克 然后说下细节,,, 其实就一个细节,就赋初值问题,要把除了f[i…
题目链接 手写一下AC自动机(我可没说我之前不是手写的) Trie上dp,每个点的贡献加上所有是他后缀的串的贡献,也就是这个点到根的fail链的和. #include <cstdio> #include <queue> #include <cstring> #include <algorithm> using namespace std; const int MAXK = 1010; const int MAXN = 1010; struct ACA{ in…
思路 简单的AC自动机上dp,暴力跳fail向子节点直接转移即可 代码 #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; int trie[400][3],Nodecnt,mark[400],fail[400],dp[1001][400],root,k,n; char t[400]; void insert(char…
洛谷题目传送门 闲话 看完洛谷larryzhong巨佬的题解,蒟蒻一脸懵逼 如果哪年NOI(放心我这样的蒟蒻是去不了的)又来个决策单调性优化DP,那蒟蒻是不是会看都看不出来直接爆\(0\)?! 还是要想点办法,不失一般性也能快捷地判定决策单调. 对于判定决策单调的分析 再补一句决策单调性的概念:状态转移方程形如\(f_i=\min/\max_{j=1}^{i-1} g_j+w_{i,j}\),且记\(f_i\)的最优决策点为\(p_i\)(也就是\(f_i\)从\(g_{p_i}+w_{i,p_…
P3043 [USACO12JAN]牛联盟Bovine Alliance 题目描述 Bessie and her bovine pals from nearby farms have finally decided that they are going to start connecting their farms together by trails in an effort to form an alliance against the farmers. The cows in each…
P3040 [USACO12JAN]贝尔分享Bale Share 题目描述 Farmer John has just received a new shipment of N (1 <= N <= 20) bales of hay, where bale i has size S_i (1 <= S_i <= 100). He wants to divide the bales between his three barns as fairly as possible. After…
[USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.The…