GYM 101933E(记忆化搜索)
用每个人的血量作为状态去搜索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(记忆化搜索)的更多相关文章
- GYM 100608G 记忆化搜索+概率 2014-2015 Winter Petrozavodsk Camp, Andrew Stankevich Contest 47 (ASC 47)
https://codeforces.com/gym/100608 题意: 两个人玩游戏,每个人有一个长为d的b进制数字,两个人轮流摇一个$[0,b-1]$的骰子,并将选出的数字填入自己的d个空位之中 ...
- Codeforces Gym 100231G Voracious Steve 记忆化搜索
Voracious Steve 题目连接: http://codeforces.com/gym/100231/attachments Description 有两个人在玩一个游戏 有一个盆子里面有n个 ...
- 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 ...
- 【每日dp】 Gym - 101889E Enigma 数位dp 记忆化搜索
题意:给你一个长度为1000的串以及一个数n 让你将串中的‘?’填上数字 使得该串是n的倍数而且最小(没有前导零) 题解:dp,令dp[len][mod]为是否出现过 填到第len位,余数为mod 的 ...
- Loppinha, the boy who likes sopinha Gym - 101875E (dp,记忆化搜索)
https://vjudge.net/contest/299302#problem/E 题意:给出一个01 0101串,然后能量计算是连续的1就按1, 2, 3的能量加起来.然后给出起始的能量,求最少 ...
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
- 【BZOJ-3895】取石子 记忆化搜索 + 博弈
3895: 取石子 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 263 Solved: 127[Submit][Status][Discuss] D ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- zoj 3644(dp + 记忆化搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...
- loj 1044(dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...
随机推荐
- java高级特性增强
第4天 java高级特性增强 今天内容安排: 1.掌握多线程 2.掌握并发包下的队列 3.了解JMS 4.掌握JVM技术 5.掌握反射和动态代理 java多线程增强 .1. java多线程基本知识 . ...
- (1)Java多线程编程核心——Java多线程技能
1.为什么要使用多线程?多线程的优点? 提高CPU的利用率 2.什么是多线程? 3.Java实现多线程编程的两种方式? a.继承Thread类 public class MyThread01 exte ...
- 时尚设计div+css免费模板
时尚设计div+css免费网页模板,时尚设计,div+css. http://www.huiyi8.com/moban/
- ES BM25 TF-IDF相似度算法设置——
Pluggable Similarity Algorithms Before we move on from relevance and scoring, we will finish this ch ...
- 【LeetCode】063. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- bzoj 3376 [Usaco2004 Open]Cube Stacking 方块游戏——带偏移量的并查集
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3376 带偏移量的并查集. #include<iostream> #include ...
- CF-816B
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- Struts2+JQuery+Json登陆实例
Struts2+JQuery+Json登陆实例 博客分类: Struts2 在搭建之前.. 首先,需要准备struts2.0框架的5个核心包, 以及jsonplugin-0.32.jar 以及js ...
- <c和指针>学习笔记1之快速上手和基本概念
1 c语言中的注释 功能:使这段代码在程序中不起作用,当然如果是功能注释,那是方便其他人阅读您的代码. 大部分情况下,多行的注释,我们采用的是这种方式,例如 /*内容*/. 这个符号不能嵌套,也就是 ...
- 数据库中rs("ABC")与rs.Fields("ABC").value的差别(Rs是RecordSet对象)
透过RecordSet取得数据的时候我们要将数据显示出来时,假设字段名称是ABCABCX = rs("ABC")对于RecordSet来说....是把ABC这个[Fileds对象] ...