# 【期望dp】bzoj4832: [Lydsy1704月赛]抵制克苏恩

## Description

。现在小Q同学会给出克苏恩的攻击力是 K ，表示克苏恩会攻击 K 次，每次会从对方场上的英雄和随从中随机选

；如果克苏恩攻击了你的英雄，你的英雄会记录受到 1 点伤害。你应该注意到了，每当克苏恩进行一次攻击，你

## 题目分析

 1 #include<cstdio>
2
3 int T,k,a,b,c;
4 double ans;
5
6 void dfs(int done, int n1, int n2, int n3, int bld, double sta)
7 {
8     if (done==k||!bld) return;
9     if (n1) dfs(done+1, n1-1, n2, n3, bld, sta*n1/(n1+n2+n3+1.0));
10     if (n2){
11         if (n1+n2+n3 < 7)
12             dfs(done+1, n1+1, n2-1, n3+1, bld, sta*n2/(n1+n2+n3+1.0));
13         else dfs(done+1, n1+1, n2-1, n3, bld, sta*n2/(n1+n2+n3+1.0));
14     }
15     if (n3){
16         if (n1+n2+n3 < 7)
17             dfs(done+1, n1, n2+1, n3, bld, sta*n3/(n1+n2+n3+1.0));
18         else dfs(done+1, n1, n2+1, n3-1, bld, sta*n3/(n1+n2+n3+1.0));
19     }
20     ans += sta/(n1+n2+n3+1.0);
21     dfs(done+1, n1, n2, n3, bld, sta/(n1+n2+n3+1.0));
22 }
23 int main()
24 {
25     freopen("cthun.in","r",stdin);
26     freopen("cthun.out","w",stdout);
27     scanf("%d",&T);
28     while (T--)
29     {
30         ans = 0;
31         scanf("%d%d%d%d",&k,&a,&b,&c);
32         dfs(0, a, b, c, 30, 1.0);
33         printf("%.2lf\n",ans);
34     }
35     return 0;
36 }

 1 #include<cstdio>
2 #include<cctype>
3
4 int T,k,a,b,c;
5 double f[53][13][13][13];
6
8 {
9     int num = 0;
10     bool fl = 0;
11     char ch = getchar();
12     for (; !isdigit(ch); ch=getchar())
13         if (ch=='-') fl = 1;
14     for (; isdigit(ch); ch=getchar())
15         num = (num<<1)+(num<<3)+ch-48;
16     if (fl) num = -num;
17     return num;
18 }
19 int main()
20 {
21     freopen("cthun.in","r",stdin);
22     freopen("cthun.out","w",stdout);
23     for (int t=1; t<=50; t++)
24         for (int i=0; i<=7; i++)
25             for (int j=0; i+j<=7; j++)
26                 for (int k=0; i+j+k<=7; k++)
27                 {
28                     double sum = i+j+k+1.0;
29                     f[t][i][j][k] += (f[t-1][i][j][k]+1)/sum;
30                     f[t][i][j][k] += f[t-1][i-1][j][k]*i/sum;
31                     if (i+j+k < 7)
32                         f[t][i][j][k] += f[t-1][i+1][j-1][k+1]*j/sum,
33                         f[t][i][j][k] += f[t-1][i][j+1][k]*k/sum;
34                     else
35                         f[t][i][j][k] += f[t-1][i+1][j-1][k]*j/sum,
36                         f[t][i][j][k] += f[t-1][i][j+1][k-1]*k/sum;
37                 }
40     return 0;
41 } 

END

posted @ 2018-10-05 16:49  AntiQuality  阅读(123)  评论(0编辑  收藏  举报