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
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 (1n,m51≤n,m≤5, 1d1001≤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 10610−6.

Examples
input
Copy
1 2 2
2
1 1
output
Copy
0.33333333
input
Copy
2 3 12
3 2
4 2 3
output
Copy
0.13773809

题意:
我方有n个人,敌方有m个人,你可以攻击d次。每次等概率击中一个血量不为0的人,被击中的人掉一点血。
问最后敌方全部阵亡的概率。
解法:
记忆化搜索+状压。
假如己方有三个人,血量2 3 3 和3 2 3 要看成同一种状态,否者会TLE或者会MLE
对敌方也是如此,但是不可以把敌我混起来。
代码:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100086;
const int inf = 2.1e9;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1);
int hp1[10],hp2[10];
int n,m,k;
map<ll,double>dp;
ll over;
ll get_state(){
    ll ans=0;
    for(int i=1;i<=6;i++){
        ans=ans*7+hp2[i];
    }
    for(int i=1;i<=6;i++){
        ans=ans*7+hp1[i];
    }
    return ans;
}
double dfs(ll state,ll t){
    if(dp.count(state)){return dp[state];}
    double &res=dp[state];
    if(state<over){return res=1.0;}
    if(t==0){return res=0.0;}
    int ans=0;
    for(int i=1;i<=6;i++){
        if(!hp1[i]){continue;}
        ans+=hp1[i];
        hp1[i]--;hp1[i-1]++;
        ll new_state=get_state();
        res+=(hp1[i]+1)*dfs(new_state,t-1);
        hp1[i]++;hp1[i-1]--;
    }
    for(int i=1;i<=6;i++){
        if(!hp2[i]){continue;}
        ans+=hp2[i];
        hp2[i]--;hp2[i-1]++;
        ll new_state=get_state();
        res+=(hp2[i]+1)*dfs(new_state,t-1);
        hp2[i]++;hp2[i-1]--;
    }
    res/=ans;
    return res;
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    int x;
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        hp1[x]++;
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&x);
        hp2[x]++;
    }
    for(int i=1;i<=6;i++){
        over=over*7+6;
    }
    printf("%.8f",dfs(get_state(),k));
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/ZGQblogs/p/10518850.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值