提交时间:2022-07-20 12:04:51

运行 ID: 52864

#include<bits/stdc++.h> using namespace std; long long sb[21],minn,n,a[20],p,q,sum; int main(){ sb[0]=1; cin>>n>>p>>q; for(int i=1;i<=n;i++)cin>>a[i]; if(q>n*p){ for(int i=1;i<n;i++){ if(a[i]==i)continue; for(int j=i+1;j<=n;j++) if(a[j]==i){ swap(a[i],a[j]); break; } sum++; } cout<<sum*p<<".00000000000000000000"; return 0; } for(int i=1;i<=20;i++)sb[i]=sb[i-1]*i; minn=sb[n]*q; for(int i=1;i<n;i++){ if(a[i]==i)continue; for(int j=i+1;j<=n;j++) if(a[j]==i){ swap(a[i],a[j]); break; } sum++; } minn=min(minn,sum*p); double ss=minn; ss*=2; ss/=(n-1)*n; ss+=p; double s=minn; s=min(s,ss); cout<<fixed<<setprecision(20)<<minn; }