# BZOJ 3029 守卫者的挑战

## 题面

### Sample Input

3 1 0
10 20 30
-1 -1 2


### Sample Output

0.300000


## 题解

DP傻题.
$f[i][j][k]$表示第$i$个完成挑战后, 总共成功$j$个挑战, 背包剩余容量为$k$的概率.

#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 200;
int main()
{
#ifndef ONLINE_JUDGE
freopen("BZOJ3029.in", "r", stdin);
#endif

int n, m, c;
scanf("%d%d%d", &n, &m, &c);
static double pr[N + 1];
for(int i = 1; i <= n; ++ i)
scanf("%lf", pr + i);
for(int i = 1; i <= n; ++ i)
pr[i] /= 100;
static int a[N + 1];
for(int i = 1; i <= n; ++ i)
scanf("%d", a + i);
static double f[N + 1][N + 1][N << 1 | 1];
memset(f, 0, sizeof(f));
f[0][0][N + std::min(c, n)] = 1;
for(int i = 0; i < n; ++ i)
for(int j = 0; j <= i; ++ j)
for(int k = N - n; k <= N + n; ++ k)
f[i + 1][j + 1][std::min(n + N, k + a[i + 1])] += f[i][j][k] * pr[i + 1],
f[i + 1][j][k] += f[i][j][k] * (1 - pr[i + 1]);
double ans = 0;
for(int i = m; i <= n; ++ i)
for(int j = N; j <= N + n; ++ j)
ans += f[n][i][j];
printf("%lf", ans);
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 200;
int main()
{
#ifndef ONLINE_JUDGE
freopen("BZOJ3029.in", "r", stdin);
#endif

int n, m, c;     scanf("%d%d%d", &n, &m, &c);     static double pr[N + 1];
for(int i = 1; i <= n; ++ i)         scanf("%lf", pr + i);     for(int i = 1;
i <= n; ++ i)         pr[i] /= 100;     static int a[N + 1];     for(int i =
1; i <= n; ++ i)         scanf("%d", a + i);     static double f[N + 1][N +
1][N << 1 | 1];     memset(f, 0, sizeof(f));     f[0][0][N + std::min(c, n)] =
1;     for(int i = 0; i < n; ++ i)         for(int j = 0; j <= i; ++ j)
for(int k = N - n; k <= N + n; ++ k)                                 f[i +
1][j + 1][std::min(n + N, k + a[i + 1])] += f[i][j][k] * pr[i + 1],
f[i + 1][j][k] += f[i][j][k] * (1 - pr[i + 1]);     double ans = 0;
for(int i = m; i <= n; ++ i)         for(int j = N; j <= N + n; ++ j)
ans += f[n][i][j];     printf("%lf", ans); }


posted @ 2017-07-09 10:48  Zeonfai  阅读(243)  评论(0编辑  收藏  举报