Problem Description
In the unimaginable popular DotA game, the hero Lich has a wonderful skill: Frost Chain, release a jumping breath of frost that jumps N times against enemy units.




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.

 

Input
There are several test cases in the input.

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.

 

Output
For each test case, output five floating numbers, indicating the death probability of each hero, as the given order, rounded to three fractional digits, and separated by a single blank.
 

Sample Input

3 100
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
 

Sample Output

0.800 0.800 0.800 0.800 0.800

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 */

最新文章

  1. FFmpeg纯净版解码 av_parser_parse2
  2. 创建外网 ext_net - 每天5分钟玩转 OpenStack(104)
  3. Screenfly – 各种设备的屏幕和分辨率下快速测试网站
  4. MySQL数据库管理常用命令
  5. 转载__UI之Frgment
  6. ABAP后台JOB数量控制
  7. MySql服务器的启动和关闭
  8. C# 中经常用到的HTTP请求类,已封装get,post,delete,put
  9. 触发TreeView的TreeNodeCheckChanged事件
  10. OC .(点)与-&gt;(箭头)用法区别
  11. 优化DOM交互
  12. Javascript 装饰器极速指南
  13. [SDOI2016]排列计数
  14. 【学习总结】GirlsInAI ML-diary day-10-if条件执行
  15. api接口简短实力
  16. ASP.NET Web API中把分页信息放Header中返回给前端
  17. 排序jq
  18. 关于变量参数的传递,python让人蛋痛的地方
  19. 139.00.003 Git学习-Git时光机之Inbox体系(三)
  20. Windows软件静默安装

热门文章

  1. Xamarin.Forms 5.0 来了
  2. swoole中websoket创建在线聊天室(php)
  3. 【JavaWeb】Cookie&amp;Session
  4. pip不是内部或外部命令解决方法
  5. ajax跨域访问http服务--jsonp
  6. 使用msys2在window下构建和使用Linux的软件
  7. kubernets之Deployment资源
  8. maven打包项目
  9. Windows安全加固
  10. ORACLE 归档日志打开关闭方法(转载)