QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357984 | #5105. Hand of the Free Marked | Doqe | WA | 0ms | 3836kb | C++20 | 864b | 2024-03-19 16:07:51 | 2024-03-19 16:07:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
long double fac(long double m)
{
long double ans=1;
for(int i=1;i<=m;++i)ans=ans*i;
return ans;
}
long double C(long double n,long double m)
{
long double ans=1;
for(int i=n-m+1;i<=n;++i)ans=ans*i;
return ans/fac(m);
}
double ans=0;
int k,m,a[100],z[102];
void dfs(int x,int s)
{
if(x==m+1)
{
if(s)return;
long double p=0,q=1;
for(int i=1;i<=m;++i)if(z[i])
p+=C(a[i],z[i]-1)/C(a[i],z[i]),q*=C(a[i],z[i]);
// cerr<<": ";for(int i=1;i<=m;++i)cerr<<z[i]<<",";cerr<<" : "<<p<<" "<<q<<" "<<1/q<<endl;
ans+=min(p*fac(k-1),1.0L)*q;return;
}
for(int i=0;i<=s;++i)
{
z[x]=i;dfs(x+1,s-i);
}
}
int main()
{
cin>>k>>m;long double n=0;
for(int i=1;i<=m;++i)cin>>a[i],n+=a[i];
dfs(1,k);
// cerr<<ans<<" "<<C(n,k)<<endl;
printf("%.12Lf\n",ans/C(n,k));
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3836kb
input:
3 3 2 1 2
output:
-nan
result:
wrong output format Expected double, but "-nan" found