用每个人的血量作为状态去搜索T飞,考虑题解中更好的搜索方式:每种血量有多少个人作为状态。这样会减去很多重复的状态,因为只要乘一下就得到了所有相同情况的和。

虽然我不会算,但是直观感受起来复杂度比较优秀。

#include <cstdio>
#include <unordered_map>
using namespace std; typedef double db;
typedef long long ll; int n, m, d, mod = 1e6;
int cnt[2][10];
unordered_map<ll, db> mp; void read(int n, int k) {
for (int a, i = 1; i <= n; i++) {
scanf("%d", &a);
cnt[k][a]++;
}
} ll tran(ll res = 0) {
for (int i = 0; i < 2; i++)
for (int j = 1; j <= 6; j++)
res = res * 10 + cnt[i][j];
return res;
} db dfs(ll t, int depth) {
if (mp.count(t)) return mp[t];
if (t % mod == 0) return mp[t] = 1;
if (depth == d) return mp[t] = 0; db res = 0; int tmp = 0;
for (int i = 0; i < 2; i++)
for (int j = 1; j <= 6; j++)
tmp += cnt[i][j];
for (int i = 0; i < 2; i++) {
for (int j = 1; j <= 6; j++) {
if (cnt[i][j]) {
cnt[i][j]--;
cnt[i][j - 1]++;
res += dfs(tran(), depth + 1) * (cnt[i][j] + 1) / tmp;
cnt[i][j]++;
cnt[i][j - 1]--;
}
}
}
return mp[t] = res;
} int main() {
scanf("%d %d %d", &n, &m, &d);
read(n, 0), read(m, 1);
return !printf("%.8lf\n", dfs(tran(), 0));
}

GYM 101933E(记忆化搜索)的更多相关文章

  1. GYM 100608G 记忆化搜索+概率 2014-2015 Winter Petrozavodsk Camp, Andrew Stankevich Contest 47 (ASC 47)

    https://codeforces.com/gym/100608 题意: 两个人玩游戏,每个人有一个长为d的b进制数字,两个人轮流摇一个$[0,b-1]$的骰子,并将选出的数字填入自己的d个空位之中 ...

  2. Codeforces Gym 100231G Voracious Steve 记忆化搜索

    Voracious Steve 题目连接: http://codeforces.com/gym/100231/attachments Description 有两个人在玩一个游戏 有一个盆子里面有n个 ...

  3. Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)

    E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...

  4. 【每日dp】 Gym - 101889E Enigma 数位dp 记忆化搜索

    题意:给你一个长度为1000的串以及一个数n 让你将串中的‘?’填上数字 使得该串是n的倍数而且最小(没有前导零) 题解:dp,令dp[len][mod]为是否出现过 填到第len位,余数为mod 的 ...

  5. Loppinha, the boy who likes sopinha Gym - 101875E (dp,记忆化搜索)

    https://vjudge.net/contest/299302#problem/E 题意:给出一个01 0101串,然后能量计算是连续的1就按1, 2, 3的能量加起来.然后给出起始的能量,求最少 ...

  6. [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索

    1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...

  7. 【BZOJ-3895】取石子 记忆化搜索 + 博弈

    3895: 取石子 Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 263  Solved: 127[Submit][Status][Discuss] D ...

  8. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. zoj 3644(dp + 记忆化搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...

  10. loj 1044(dp+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...

随机推荐

  1. 虚拟参考站(VRS)

    来源:https://www.sohu.com/a/149415053_391994 一.高精度定位 VRS是虚拟参考站(Virtual Reference Station)的简称.这项技术是CORS ...

  2. Listen81

    Nut-Cracking Chimps Demonstrate Cultural Differences One family generally dines on Chinese takeout w ...

  3. STL中mem_fun和mem_fun_ref的用法

    例如:假设有如下的代码: class Employee { public: int DoSomething(){} } std::vector<Employee> Emps; 假设我们要调 ...

  4. 遁入NOIP记

    回归noip啦 给自己定个小目标 500分起步 在这里列一下需要搞的东西OvO 1.算法基础 模拟 贪心 二分 分治 2.搜索 / 记忆化搜索 剪枝 对抗搜索 3.dp 状压 组合数学 树D 单队 D ...

  5. 1123 Is It a Complete AVL Tree(30 分)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  6. 洛谷 2585 [ZJOI2006]三色二叉树——树形dp

    题目:https://www.luogu.org/problemnew/show/P2585 可以把不是绿色的记成一种.仔细一想不会有冲突.如果自己是绿色,孩子的不同颜色不会冲突:如果自己不是绿色,自 ...

  7. jdk、tomcat如何配置环境变量

    一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2.安装Tomc ...

  8. 百度地图API的第一次接触

    因为项目的需求,第一次接触了百度API. 第一步:引用百度地图API的脚本 如果在局域网环境中,要把地图文件和js文件都要下载下来 <script type="text/javascr ...

  9. 网络工具 NetCat

    http://netcat.sourceforge.net/ windows 版本 https://joncraton.org/blog/46/netcat-for-windows/ https:// ...

  10. ReportEvent的正确使用方式

    向操作系统的事件管理器报告重大信息是一种非常有用的方式,特别是对于没有界面的后台服务而言.如果你对Windows编程有一定了解,应该很快就能想到使用ReportEvent这个API,然后快速写出下面的 ...