forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10081.cpp
49 lines (46 loc) · 766 Bytes
/
10081.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int n, k;
double f[12][102] = {0}, ans = 0, pow_;
int main()
{
while (scanf("%d%d", &k, &n) == 2)
{
memset(f, 0, sizeof(f));
for (int i = 0; i <= k; i++)
{
f[i][1] = 1;
}
for (int j = 2; j <= n; j++)
{
for (int i = 0; i <= k; i++)
{
if (i == 0)
{
f[i][j] = f[i][j - 1] + f[i + 1][j - 1];
}
else if (i == k)
{
f[i][j] = f[i - 1][j - 1] + f[i][j - 1];
}
else
{
f[i][j] = f[i - 1][j - 1] + f[i][j - 1] + f[i + 1][j - 1];
}
}
}
ans = 0;
for (int i = 0; i <= k; i++)
{
ans += f[i][n];
}
k++;
pow_ = (double)k;
for (int i = 1; i < n; i++)
{
pow_ *= k;
}
printf("%.5lf\n", ans / pow_ * 100, ans, pow_);
}
return 0;
}