-
Notifications
You must be signed in to change notification settings - Fork 0
/
tightword.cpp
46 lines (37 loc) · 955 Bytes
/
tightword.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <map>
#include <sstream>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pii;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int k,n;
double ans[105][15],sum;
while(cin>>k>>n){
memset(ans,0.0,sizeof(ans));
sum=0.0;
for(int i=1;i<=k+1;i++)
ans[1][i] = 1.0 / (double)(k+1);
for(int i=2;i<=n;i++){
for(int j=1;j<=k+1;j++)
ans[i][j] = (ans[i-1][j-1] + ans[i-1][j] + ans[i-1][j+1]) / (double)(k+1);
}
for(int i=1;i<=k+1;i++)
sum += ans[n][i];
if(k==0)
sum=1.0;
cout << fixed << setprecision(5) << sum*100 <<'\n';
}
return 0;
}