提交时间:2022-07-20 13:25:48

运行 ID: 53016

#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; int main() { cin>>n>>a>>b; for(int i=1; i<=n; i++) scanf("%d",&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<=n/2; 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]=(S[i-1][j]*(i-1)+S[i-1][j-1]); f=1; for(int i=n/2+1; 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; }