E. Explosion Exploit
time limit per test

2.0 s

memory limit per test

256 MB

input

standard input

output

standard output

In a two player card game, you have nn minions on the board and the opponent has mm minions. Each minion has a health between 11 and 66.

You are contemplating your next move. You want to play an "Explosion" spell which deals dd units of damage randomly distributed across all minions. The damage is dealt one unit at a time to some remaining minion on the board. Each living minion (including your own) has the same chance of receiving each unit of damage. When a minion receives a unit of damage, its health is decreased by one. As soon as the health of a minion reaches zero, it is immediately removed from the board, before the next damage is dealt. If there are no minions left on the board, any excess damage caused by the spell is ignored.

Given the current health of all minions, what is the probability that the Explosion will remove all of the opponent's minions? Note that it does not matter if all your own minions die in the process as well, and the damage continues to be dealt even if all your own minions are gone.

Input

The first line of input contains the three integers nn, mm, and dd (1≤n,m≤51≤n,m≤5, 1≤d≤1001≤d≤100). Then follows a line containing nn integers, the current health of all your minions. Finally, the third line contains mm integers, the current health of all the opponent's minions. All healths are between 11 and 66 (inclusive).

Output

Output the probability that the Explosion removes all the opponent's minions, accurate up to an absolute error of 10−610−6.

Examples
input

Copy
  1. 1 2 2
    2
    1 1
output

Copy
  1. 0.33333333
input

Copy
  1. 2 3 12
    3 2
    4 2 3
output

Copy
  1. 0.13773809
  2.  
  3. 题意:
    我方有n个人,敌方有m个人,你可以攻击d次。每次等概率击中一个血量不为0的人,被击中的人掉一点血。
    问最后敌方全部阵亡的概率。
    解法:
    记忆化搜索+状压。
    假如己方有三个人,血量2 3 3 3 2 3 要看成同一种状态,否者会TLE或者会MLE
    对敌方也是如此,但是不可以把敌我混起来。
    代码:
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<stack>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<ctime>
  12. #define fuck(x) cout<<#x<<" = "<<x<<endl;
  13. #define ls (t<<1)
  14. #define rs ((t<<1)+1)
  15. using namespace std;
  16. typedef long long ll;
  17. typedef unsigned long long ull;
  18. const int maxn = ;
  19. const int inf = 2.1e9;
  20. const ll Inf = ;
  21. const int mod = ;
  22. const double eps = 1e-;
  23. const double pi = acos(-);
  24. int hp1[],hp2[];
  25. int n,m,k;
  26. map<ll,double>dp;
  27. ll over;
  28. ll get_state(){
  29. ll ans=;
  30. for(int i=;i<=;i++){
  31. ans=ans*+hp2[i];
  32. }
  33. for(int i=;i<=;i++){
  34. ans=ans*+hp1[i];
  35. }
  36. return ans;
  37. }
  38. double dfs(ll state,ll t){
  39. if(dp.count(state)){return dp[state];}
  40. double &res=dp[state];
  41. if(state<over){return res=1.0;}
  42. if(t==){return res=0.0;}
  43. int ans=;
  44. for(int i=;i<=;i++){
  45. if(!hp1[i]){continue;}
  46. ans+=hp1[i];
  47. hp1[i]--;hp1[i-]++;
  48. ll new_state=get_state();
  49. res+=(hp1[i]+)*dfs(new_state,t-);
  50. hp1[i]++;hp1[i-]--;
  51. }
  52. for(int i=;i<=;i++){
  53. if(!hp2[i]){continue;}
  54. ans+=hp2[i];
  55. hp2[i]--;hp2[i-]++;
  56. ll new_state=get_state();
  57. res+=(hp2[i]+)*dfs(new_state,t-);
  58. hp2[i]++;hp2[i-]--;
  59. }
  60. res/=ans;
  61. return res;
  62. }
  63. int main(){
  64. scanf("%d%d%d",&n,&m,&k);
  65. int x;
  66. for(int i=;i<=n;i++){
  67. scanf("%d",&x);
  68. hp1[x]++;
  69. }
  70. for(int i=;i<=m;i++){
  71. scanf("%d",&x);
  72. hp2[x]++;
  73. }
  74. for(int i=;i<=;i++){
  75. over=over*+;
  76. }
  77. printf("%.8f",dfs(get_state(),k));
  78. return ;
  79. }

Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)的更多相关文章

  1. URAL 1152. False Mirrors (记忆化搜索 状压DP)

    题目链接 题意 : 每一颗子弹破坏了三个邻近的阳台.(第N个阳台是与第1个相邻)射击后后的生存的怪物都对主角造成伤害- 如此,直到所有的怪物被消灭,求怎样射击才能受到最少伤害. 思路 : 状压,数据不 ...

  2. lightoj 1158 - Anagram Division(记忆化搜索+状压)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1158 题解:这题看起来就像是记忆搜索,由于s很少最多就10位所以可以考虑用状压 ...

  3. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  4. codeforces 284 D. Cow Program(记忆化搜索)

    题目链接:http://codeforces.com/contest/284/problem/D 题意:给出n个数,奇数次操作x,y都加上a[x],偶数次操作y加上a[x],x减去a[x],走出了范围 ...

  5. Codeforces 294B Shaass and Bookshelf(记忆化搜索)

    题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #inc ...

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

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

  7. Gym 100650H Two Ends DFS+记忆化搜索

    Problem H: Two EndsIn the two-player game “Two Ends”, an even number of cards is laid out in a row. ...

  8. Codeforces 540D Bad Luck Island - 概率+记忆化搜索

    [题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...

  9. Codeforces 354B 博弈, DP,记忆化搜索

    题意:现在有一个字符矩阵,从左上角出发,每个人交替选择一个字符.如果最后字符a数目大于字符b,那么第一个人获胜,否则b获胜,否则平均.现在双方都不放水,问最后结果是什么? 思路:这题需要注意,选择的字 ...

随机推荐

  1. 无法启动此程序,因为计算机丢失MSVCR110.dll

    解决方法下: 1.首先是打开浏览器,在浏览器的地址栏里输入 http://www.microsoft.com/zh-CN/download/details.aspx?id=30679 这个网址来进行相 ...

  2. Lodop打印html数字间隔不一致

    在font-size属性控制数字大小的时候,可能会出现数字间隔有问题,间隔不一致,可尝试用其他字体大小试试,一般字体越小,越可能出现问题. 如图,前两个打印项都是form1,样式一个是style1,一 ...

  3. eclipse 等号左边代码补全

    1: 2. 3.完成  “ctrl + shift + l” 代码补全成功

  4. nvidia-smi实时刷新并高亮显示状态

    watch -n 1 -d nvidia-smi 间隔1秒刷新

  5. vuex2.0 基本使用(3) --- getter

    有的组件中获取到 store 中的state,  需要对进行加工才能使用,computed 属性中就需要写操作函数,如果有多个组件中都需要进行这个操作,那么在各个组件中都写相同的函数,那就非常麻烦,这 ...

  6. 【数学建模】day10-主成分分析

    0. 关于主成分分析的详细理解以及理论推导,这篇blog中讲的很清楚. 主成分分析是一种常用手段.这应该与因子分析等区别开来,重点在于理解主成分分析的作用以及什么情况下使用主成分分析,本文重点讲解如何 ...

  7. 利用random模块生成验证码

    random模块 该模块用于数学或者数据相关的领域,使用方法非常简单下面介绍常用的放法 1.随机小数 random.random() 2.随机整数random.randint(1,5) # 大于等于1 ...

  8. Spring 使用介绍(十二)—— Spring Task

    一.概述 1.jdk的线程池和任务调用器分别由ExecutorService.ScheduledExecutorService定义,继承关系如下: ThreadPoolExecutor:Executo ...

  9. 读取CSV到DataTable

    using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using Sy ...

  10. bzoj 2957 楼房重建 (线段树+思路)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2957 思路: 用分块可以很简单的过掉,但是这道题也可以用线段树写. 分类讨论左区间最大值对 ...