QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189246 | #5105. Hand of the Free Marked | bulijiojiodibuliduo# | TL | 1935ms | 3828kb | C++17 | 1.3kb | 2023-09-27 04:11:57 | 2023-09-27 04:11:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=20;
db comb[N][N],fac,way,tot;
int cnt[N],a[N];
int k,m;
void dfs(int d,int s) {
if (d==m) {
if (s<k) return;
db R=1,L=0;
rep(i,0,m) R*=comb[i][cnt[i]];
rep(i,0,m) if (cnt[i]>0) {
db w=1;
rep(j,0,m) w*=comb[j][cnt[j]-(j==i)];
L+=w;
}
L=L*fac;
tot+=R;
way+=min(L,R);
} else {
rep(i,0,a[d]+1) if (s+i<=k) {
cnt[d]=i;
dfs(d+1,s+i);
}
}
}
int main() {
scanf("%d%d",&k,&m);
fac=1;
rep(i,1,k) fac*=i;
rep(i,0,m) {
scanf("%d",&a[i]);
comb[i][0]=1;
rep(j,1,k+1) {
comb[i][j]=comb[i][j-1]*(a[i]-j+1)/j;
}
}
dfs(0,0);
printf("%.10f\n",way/tot);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
3 3 2 1 2
output:
1.0000000000
result:
ok answer is 1.0000000000
Test #2:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
3 4 1 3 1 15
output:
0.7719298246
result:
ok answer is 0.7719298246
Test #3:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
4 1 27
output:
1.0000000000
result:
ok answer is 1.0000000000
Test #4:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
4 3 1 2 28
output:
0.9739710790
result:
ok answer is 0.9739710790
Test #5:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
4 3 1 3 28
output:
0.9772246941
result:
ok answer is 0.9772246941
Test #6:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
5 1 130
output:
0.9523809524
result:
ok answer is 0.9523809524
Test #7:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
5 3 2 16 200
output:
0.7490392123
result:
ok answer is 0.7490392123
Test #8:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
4 10 1 2 3 4 1 2 3 4 5 100
output:
0.6954998646
result:
ok answer is 0.6954998646
Test #9:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
4 10 1 20 3 4 1 2 40 4 5 500
output:
0.2435721816
result:
ok answer is 0.2435721816
Test #10:
score: 0
Accepted
time: 868ms
memory: 3736kb
input:
3 2 152333146 373955979
output:
0.0000000228
result:
ok answer is 0.0000000228
Test #11:
score: 0
Accepted
time: 1935ms
memory: 3800kb
input:
2 5 263121 2244976 14139709 57922752 200667899
output:
0.0000000363
result:
ok answer is 0.0000000363
Test #12:
score: -100
Time Limit Exceeded
input:
2 9 8693409 192044828 270204 207696017 4714758 43866747 54411633 159493424 1230327