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

运行 ID: 52728

#include<bits/stdc++.h> using namespace std; const int N=30; int n,a,b,k[N]; double E=0.00000000; int read(){ register int res=0,w=1; register char ch=getchar(); while(ch<'0'||ch>'9'){ ch=='-'?w=-1:w=w; ch=getchar(); } while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch^48),ch=getchar(); return res*w; } int p[N],cnt; double solve(){ double ans=0.00000000; for(register int i=1;i<=n;i++){ if(p[i]==i) continue; swap(p[i],p[p[i]]); ans+=a; } return ans; } int main(){ n=read(); a=read(); b=read(); for(register int i=1;i<=n;i++){ k[i]=read(); if(k[i]!=i) p[k[i]]=i,cnt++; } long long jc=1; for(register int i=2;i<=n;i++){ jc=jc*i; } if(cnt==0) puts("0.00000000000000000000"); else if(b>n*a){ printf("%.8lf",solve()); } else{ printf("%.8lf",(double)jc*b); } } //20!=2432902008176640000