SPOJ:Red John is Back(DP)】的更多相关文章

Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he leaves behind is a puzzle for Patrick Jane to solve. He also texts Teresa Lisbon that if Patrick is successful, he will turn himself in. The puzzle be…
[题目链接] http://www.spoj.com/problems/LCS2/en/ [题意] 求若干个串的最长公共子串. [思路] SAM+DP 先拿个串建个SAM,然后用后面的串匹配,每次将所有的匹配长度记录在状态上取min,然后对所有状态取max即答案. 需要更新fa,因为fa[p]一定比p更优,但匹配的时候可能只更新了p而没有更新fa[p],所以还需要递推一边. 注意mn[p]初始化为l[p] [代码] #include<cstdio> #include<cstring>…
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1536MB Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1)      Every even digit…
Little Red Riding Hood Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 853  Solved: 129[Submit][Status][Web Board] Description Once upon a time, there was a little girl. Her name was Little Red Riding Hood. One day, her grandma was ill. Little Red Ri…
Red is good Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description 桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元.可以随时停止翻牌,在最优策略下平均能得到多少钱. Input 一行输入两个数R,B. Output 在最优策略下平均能得到多少钱.输出答案时,小数点后第六位后的全部去掉,不要四舍五入. Sample Input…
You are given a rooted tree with n nodes. The nodes are numbered 1..n. The root is node 1, and m of the nodes are colored red, the rest are black. You would like to choose a subset of nodes such that there is no node in your subset which is an ancest…
我 是 Z Z 概率好玄啊(好吧是我太弱.jpg Description 桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元.可以随时停止翻牌,在最优策略下平均能得到多少钱. 数据范围与提示 输出答案时,小数点后第六位后的全部去掉,不要四舍五入. Solution 乍一看感觉是道普通求期望,然后就在错误的路上速度与激情..其实不难,但也是道挺好的概率dp 由于要求的是最佳方案,所以并不是所有方案的平均值,即不能把期望作为最终答案.所以该…
i 表示节点 i ,j=0表示不选择其父节点,j=1表示选择其父节点.f 为其父节点. 取 每个节点选择/不选择 两者中较小的那个. 一组数据: 151 21 31 41 1010 910 1112 1012 1410 1313 154 55 74 66 8 答案是6 #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector…
题目链接 一个数称为平衡数, 满足他各个数位里面的数, 奇数出现偶数次, 偶数出现奇数次, 求一个范围内的平衡数个数. 用三进制压缩, 一个数没有出现用0表示, 出现奇数次用1表示, 出现偶数次用2表示, 这样只需要开一个20*60000的数组. #include<bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y)…
题目链接 \(Description\) 给定长为\(n\)的数组\(c_i\)和\(m\),求长为\(n\)的序列\(a_i\)个数,满足:\(c_i\not\mid a_i,\quad a_i\&a_{i+1}=0\). \(n\leq 50,m\leq 15,0\leq a_i<2^m,0<c_i\leq 2^m\). \(Solution\) DP.限制都是与值有关的,所以令\(f_i\)表示以\(i\)这个数结尾的序列\(a\)的个数. 转移即\(f_i=\sum_{j,i\…