用每个人的血量作为状态去搜索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. 分享知识-快乐自己:MySQL中的约束,添加约束,删除约束,以及一些其他修饰

    创建数据库: CREATE DATABASES 数据库名: 选择数据库: USE 数据库名: 删除数据库: DROP DATAVBASE 数据库名: 创建表: CREATE TABLE IF NOT ...

  2. 清除float浮动三种方式

    Float的作用? w3c的官方解释: Content flows down the right side of a left-floated box and down the left side o ...

  3. COM组件宏观认识

    一直搞不清楚COM到底是个什么东西,记录一些个人感想,可能很多错误的,慢慢消化. 一.宏观认识: 1.COM(组件对象模型)是一种标准,规则,要求,即即于建筑设计指标要求. 2.语言无关性,因为是建立 ...

  4. 【Lintcode】094.Binary Tree Maximum Path Sum

    题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tr ...

  5. C# Unit Test 备注

    1. UT工程的编译一定要让依赖的dll在同一目录,即和测试目标dll运行的环境一样. 比如 Demo-UT测试Demo工程, 则Demo工程依赖的所有dll必须和Demo输出的可执行环境Demo.d ...

  6. webapi 跨域 (MVC-Web API: 405 method not allowed问题 )

    使用webapi cors 1.安装包:Install-Package Microsoft.AspNet.WebApi.Cors –IncludePrerelease 2.在webapiconfig. ...

  7. MultiBinding的StringFormat参数问题

    在wpf的绑定中,我们会用到多值绑定,如下: <MultiBinding Mode="OneWay" StringFormat="{3}({0}/{1}):{2}& ...

  8. hadoop学习路线(转)

    刚刚入门hadoop,如何去学习hadoop.google一篇学习路线图,与童鞋们共勉: 转自:http://blog.csdn.net/zhoudaxia/article/details/88017 ...

  9. 《精通Spring4.X企业应用开发实战》读后感第五章(<bean>之间的关系\整合多个配置文件)

  10. The Truth About GCHandles

    I've heard several people asking why GCHandle doesn't implement IDisposable, considering it wraps an ...