forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
63 lines (54 loc) · 1.81 KB
/
C.cpp
File metadata and controls
63 lines (54 loc) · 1.81 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
#define double long double
int n, m, a[111], x[111], saven;
double f[2][200111], sum[2][200111];
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cout << (fixed) << setprecision(12);
while (cin >> n >> m) {
int sumA = 0;
FOR(i,1,n) {
int x; cin >> x;
--x;
a[i] = x;
sumA += x;
}
if (m == 1) {
cout << 1.0 << endl;
continue;
}
FOR(i,1,n) {
int cur = i % 2;
memset(f[cur], 0, sizeof f[cur]);
if (i == 1) {
REP(val,m*i)
if (val < m && val != a[i]) f[cur][val] = 1;
}
else {
REP(val,m*i) {
f[cur][val] = sum[1-cur][val];
if (val >= m)
f[cur][val] -= sum[1-cur][val-m];
if (val >= a[i]) f[cur][val] -= f[1-cur][val - a[i]];
}
}
REP(val,m*(i+1)) {
sum[cur][val] = f[cur][val];
if (val > 0)
sum[cur][val] += sum[cur][val-1];
}
}
double t = sum[n % 2][sumA-1];
REP(turn,n) t /= (m-1);
cout << t * (m-1.0) + 1 << endl;
}
}