hdu3559 Frost Chain (概率dp+记忆化搜索)

Today iSea play the role of Lich, at first he randomly chooses an enemy hero to release the skill, then the frost jumps for N times. Each time, it make a damage of one HP unit on this hero (including the first time), then bounces to another hero (can’t be himself)
if their distance is no more than D and this hero is alive of course, also randomly. Here random means equal probability.
Now we know there are always only five enemy heroes, and also their coordinates and HP value. iSea wonders the death probability of each hero. One hero is dead if its HP is equal to or less than zero.
Each test case begin with two integers N and D (1 <= N <= 25, 1 <= D <= 10000).
The following line contains ten integers, indicating the coordinates of the five opponents, and -10000 ≤ x, y ≤ 10000.
Then five integers follows, indicating the HP (1 <= HP <= 5) of five opponents.
The input terminates by end of file marker.
0 1 0 2 0 3 0 4 0 5
1 1 1 1 1
3 1
0 1 0 2 0 3 0 4 0 5
1 1 1 1 1
0.500 0.800 0.800 0.800 0.500
题意:告诉你5个敌人的位置以及他们各自的血量,你有n次机会选择距离和你小于等于d且未被杀死的敌人进行攻击,一开始先选择一个敌人进行攻击,这次攻击不算在n次攻击里面的,然后问你最后每个敌人被杀死的概率。这题网上竟搜不到题解,写了很久才写对。。
思路:开一个8维的dp,用dp[pos][shengyu][t1][t2][t3][t4][t5][idx]表示现在在第i个人身上,还剩几次打击机会,每个人剩余的血量这个状态下继续搜下去杀死每个人所加的概率。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define maxn 150
struct node{
int x,y;
}a[10];
int g[10][10];
int n,m;
double dp[5][26][6][6][6][6][6][6];
double ans[5];
int cas;
void init()
{
int i,j;
for(i=0;i<5;i++){
for(j=0;j<5;j++){
if((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)<=m*m )g[i][j]=1;
else g[i][j]=0;
}
}
}
void dfs(int pos,int shengyu,int t[],double p)
{
int i,j;
if(dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]==cas){
for(i=0;i<5;i++){
ans[i]+=dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]*p;
}
return;
}
if(shengyu==0){
for(i=0;i<5;i++){
if(t[i]==0){
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=1;
ans[i]+=p;
}
else{
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=0;
}
}
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;
return;
}
int cnt=0;
for(i=0;i<5;i++){
if(pos!=i && t[i] && g[pos][i])cnt++;
}
if(cnt==0){
for(i=0;i<5;i++){
if(t[i]==0){
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=1;
ans[i]+=p;
}
else{
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=0;
}
}
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;
return;
}
double c[10];
for(i=0;i<5;i++)c[i]=ans[i];
for(i=0;i<5;i++){
if(i!=pos && t[i] && g[pos][i]){
t[i]--;
dfs(i,shengyu-1,t,p/(cnt*1.0) );
t[i]++;
}
}
dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;
for(i=0;i<5;i++)dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=(ans[i]-c[i])/p;
}
int main()
{
int i,j,k,t,h,kk,qq,q;
int b[10];
cas=0;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(ans,0,sizeof(ans));
cas++;
for(i=0;i<5;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
for(i=0;i<5;i++){
scanf("%d",&b[i]);
}
init();
for(i=0;i<5;i++){
b[i]--;
dfs(i,n,b,0.2);
b[i]++;
}
printf("%.3f %.3f %.3f %.3f %.3f\n",ans[0],ans[1],ans[2],ans[3],ans[4]);
}
return 0;
}
/*
3 100
0 1 0 2 0 3 0 4 0 5
3 4 2 1 5
0.000 0.000 0.145 0.663 0.000
4 100
0 1 0 2 0 3 0 4 0 5
3 3 3 1 1
0.015 0.015 0.015 0.784 0.784
*/
hdu3559 Frost Chain (概率dp+记忆化搜索)的更多相关文章
- HDU 5001 概率DP || 记忆化搜索
2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP 測 ...
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
- HDU - 5001 Walk(概率dp+记忆化搜索)
Walk I used to think I could be anything, but now I know that I couldn't do anything. So I started t ...
- CodeForces 398B 概率DP 记忆化搜索
题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了 ...
- 【bzoj5123】[Lydsy12月赛]线段树的匹配 树形dp+记忆化搜索
题目描述 求一棵 $[1,n]$ 的线段树的最大匹配数目与方案数. $n\le 10^{18}$ 题解 树形dp+记忆化搜索 设 $f[l][r]$ 表示根节点为 $[l,r]$ 的线段树,匹配选择根 ...
- 【BZOJ】1415 [Noi2005]聪聪和可可 期望DP+记忆化搜索
[题意]给定无向图,聪聪和可可各自位于一点,可可每单位时间随机向周围走一步或停留,聪聪每单位时间追两步(先走),问追到可可的期望时间.n<=1000. [算法]期望DP+记忆化搜索 [题解]首先 ...
- [题解](树形dp/记忆化搜索)luogu_P1040_加分二叉树
树形dp/记忆化搜索 首先可以看出树形dp,因为第一个问题并不需要知道子树的样子, 然而第二个输出前序遍历,必须知道每个子树的根节点,需要在树形dp过程中记录,递归输出 那么如何求最大加分树——根据中 ...
- poj1664 dp记忆化搜索
http://poj.org/problem?id=1664 Description 把M个相同的苹果放在N个相同的盘子里,同意有的盘子空着不放,问共同拥有多少种不同的分法?(用K表示)5.1.1和1 ...
- 状压DP+记忆化搜索 UVA 1252 Twenty Questions
题目传送门 /* 题意:给出一系列的01字符串,问最少要问几个问题(列)能把它们区分出来 状态DP+记忆化搜索:dp[s1][s2]表示问题集合为s1.答案对错集合为s2时,还要问几次才能区分出来 若 ...
随机推荐
- 数据库表空间收缩之pg_squeeze,pg_repack
数据库表空间收缩之pg_squeeze,pg_repack 目录 数据库表空间收缩之pg_squeeze,pg_repack pg_squeeze1.2 原理 优点 安装 使用 pgstattuple ...
- Head First 设计模式 —— 09. 模版方法 (Template Method) 模式
模板方法模式 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. P289 特点 主导算法框架,并且保护这个算法 P28 ...
- Java 中 Executors.newSingleThreadExecutor() 与Executors.newFixedThreadPool(1)有什么区别
在研究Executors提供的线程池时自然会想到标题这个问题,既然已经有了newFixedThreadPool,为什么还要存在newSingleThreadExecutor这个方法.难道newFixe ...
- Linux下的upx命令学习
upx学习 今天我们来学习一款给应用加壳的软件,叫做upx(the Ultimate Packer for eXecutables) 首先我们先看下它**百科的释义: UPX (the Ultimat ...
- Neo4j 图数据库查询
Cypher 介绍 Cypher 介绍:作为Neo4j的查询语言,"Cypher"是一个描述性的图形查询语言,允许不必编写图形结构的遍历代码对图形存储有表现力和效率的查询.Cyph ...
- Error: Could not request certificate: No route to host - connect(2)
[root@puppetclient ~]# puppet agent --server 192.168.127.137 --testInfo: Creating a new SSL key for ...
- dig的安装和使用
-bash: dig: command not found 解决办法: yum -y install bind-utils dig www.baid bu.com 查看a记录 dig www.ba ...
- 【Linux】使用 iperf 测试 Linux 服务器带宽
iperf 简介 iperf 是一个用于测试网络带宽的命令行工具,可以测试服务器的网络吞吐量.目前发现两个很实用的功能: 测试服务器网络吞吐量:如果我们需要知道某台服务器的「最大」网络带宽,那么最好在 ...
- LeetCode897. 递增顺序查找树
题目 法一.自己 1 class Solution { 2 public: 3 vector<int>res; 4 TreeNode* increasingBST(TreeNode* ro ...
- os.walk() 遍历目录下的文件夹和文件
os.walk(top, topdown=True, onerror=None, followlinks=False) top:顶级目录 os.walk()返回一个三元tupple(dirpath, ...