1、随机抽到正面朝上，翻转后a-1枚朝上，b+1枚朝下，概率是a/n

2、随机抽到反面朝上，翻转后a+1枚朝上，b+1枚朝下，概率是b/n

```#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b, p;
double f[5][5005], ans;
int main(){
scanf("%d%d%d%d", &n, &a, &b, &m);
f[0][a] = 1;
for(i=1; i<=m; i++){
for(j=0; j<=n; j++){
f[i&1][j] = 0;
if(j < n) f[i&1][j] += f[i-1&1][j+1] * (j+1) / n;
if(j) f[i&1][j] += f[i-1&1][j-1] * (n-j+1) / n;
}
}
for(i=1; i<=n; i++) ans += i * f[m&1][i];
printf("%.8lf\n", ans);
return 0;
}```

```#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b;
double f[5005][5005], ans;
int main(){
scanf("%d%d%d%d", &n, &a, &b, &m);
f[0][a] = 1;
for(i=1; i<=m; i++){
for(j=0; j<=n; j++){
if(j < n) f[i][j] += f[i-1][j+1] * (j+1) / n;
if(j) f[i][j] += f[i-1][j-1] * (n-j+1) / n;
}
}
for(i=1; i<=n; i++) ans += i * f[m][i];
printf("%.6lf\n", ans);
return 0;
}```

```#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b;
double f[5005][5005], ans;
int main(){
scanf("%d%d%d%d", &n, &a, &b, &m);
f[0][a] = 1;
for(i=0; i<m; i++){
for(j=0; j<=n; j++){
if(j) f[i+1][j-1] += f[i][j] * j / n;
f[i+1][j+1] += f[i][j] * (n-j) / n;
}
}
for(i=1; i<=n; i++) ans += i * f[m][i];
printf("%.8lf\n", ans);
return 0;
}```