提交时间:2022-07-20 11:51:08

运行 ID: 52720

#include<cstdio> int n,a,b; int s[22],pos[22]; inline void swap(int &x,int &y){ int t=x; x=y; y=t; } int main(){ scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;++i) scanf("%d",s+i),pos[s[i]]=i; double sum=0; for(int i=1;i<=n;++i) if(s[i]!=i){ int to=pos[i]; swap(pos[i],pos[s[i]]); swap(s[i],s[to]); sum+=a; } double ans2=0,now=1; for(int i=2;i<=n;++i) now/=i; now=1-now; double g=now; for(int i=1;i<=1000000;++i) ans2+=i*now,now*=g; double ans=sum<ans2?sum:ans2; printf("%.15lf\n",ans); return 0; }