提交时间:2022-07-20 13:28:22
运行 ID: 53020
#include<cstdio> #include<iostream> using namespace std; int n,A[21],pos[21],cnt; double a,b,eps=1e-9,ans,S[21][21],f=1; signed main() { cin>>n>>a>>b; for(int i=1; i<=n; i++) cin>>A[i],pos[A[i]]=i; for(int i=1; i<=n; i++) if(A[i]!=i) { cnt++; pos[A[i]]=pos[i]; swap(A[i],A[pos[i]]); pos[i]=i; } for(int i=1; i<=min(n,6); i++) f*=(double)i; S[0][0]=1/f; for(int i=1; i<=n; i++) for(int j=1; j<=i; j++) S[i][j]=((double)S[i-1][j]+S[i-1][j-1]); f=1; for(int i=min(n+1,7); i<=n; i++) f*=(double)i; ans=(double)cnt*a; for(int i=0; i<cnt; i++) if(S[n][n-i]>eps) ans=min(ans,b*f/S[n][n-i]+(double)a*i); printf("%.12f",ans); return 0; }