-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathWater Overflow.cpp
55 lines (44 loc) · 1.06 KB
/
Water Overflow.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
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
int main(){
//code
int t;
cin>>t;
while(t--){
double k;
int i,j;
cin>>k;
cin>>i;
cin>>j;
if(j>i){
cout<<0<<endl;
continue;
}
double dp[ (i)*(i+1) / 2 ];
memset(dp, 0, sizeof(dp));
dp[0]=k;
int index=0;
for(int row=1;row<=i;row++){
for(int col=1;col<=row;col++){
k=dp[index];
if(k>=1){
dp[index]=1;
}
else{
dp[index]=k;
}
if(k>1){
k=k-1;
}
else {
k=0;
}
dp[row+index]+=k/2;
dp[row+1+index]+=k/2;
index++;
}
}
cout << fixed << setprecision(5)<<dp[ (i*(i-1)/2) + j -1 ]<<endl;
}
return 0;
}