QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368176#8325. 重塑时光JohnAlfnov100 ✓384ms9432kbC++202.6kb2024-03-26 21:30:242024-03-26 21:30:25

Judging History

你现在查看的是最新测评结果

  • [2024-03-26 21:30:25]
  • 评测
  • 测评结果:100
  • 用时:384ms
  • 内存:9432kb
  • [2024-03-26 21:30:24]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int powdv(int x,int y=mod-2){
	int ans=1;
	while(y){
		if(y&1)ans=1ll*ans*x%mod;
		y>>=1,x=1ll*x*x%mod;
	}
	return ans;
}
int n,m,k;
int u[155],v[155];
int z1[1<<15],ct[1<<15];
bitset<25>mp[25];
bitset<125>b1[1<<15],b2[1<<15];
int gl[25],C[35][35];
int di[25];
int mb[1<<15];
struct pol{
	int a[16];
}jb,bj;
pol operator+(pol a,pol b){
	pol c;
	for(int i=0;i<=n;++i)c.a[i]=(a.a[i]+b.a[i])%mod;
	return c;
}
pol operator-(pol a,pol b){
	pol c;
	for(int i=0;i<=n;++i)c.a[i]=(a.a[i]-b.a[i]+mod)%mod;
	return c;
}
pol operator*(pol a,pol b){
	pol c;
	for(int i=0;i<=n;++i)c.a[i]=1ll*a.a[i]*b.a[i]%mod;
	return c;
}
pol operator*(int a,pol b){
	pol c;
	for(int i=0;i<=n;++i)c.a[i]=1ll*a*b.a[i]%mod;
	return c;
}
pol f[1<<15],h[1<<15];
int y[25];
int a1[25],a2[25];
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=2*n+1;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	di[0]=1;
	for(int i=1;i<=n;++i)di[i]=1ll*i*di[i-1]%mod;
	int pd=powdv(C[n+k][n]);
	for(int i=0;i<n&&i<=k;++i){
		gl[i]=1ll*1*C[k+1][i+1]%mod*pd%mod;
	}
	for(int i=1;i<=m;++i){
		scanf("%d%d",&u[i],&v[i]);
		mp[u[i]][v[i]]=1;
	}
	for(int i=1;i<(1<<n);++i){
		for(int j=1;j<=m;++j){
			int A=(i>>(u[j]-1))&1,B=(i>>(v[j]-1))&1;
			if(A)b1[i][j]=1,mb[i]|=1<<(v[j]-1);
			if(B)b2[i][j]=1;
		}
	}
	z1[0]=1;
	for(int i=0;i<(1<<n);++i)for(int j=1;j<=n;++j){
		if(i&(1<<(j-1)))continue;
		int fl=1;
		for(int k=1;k<=n;++k)if(mp[k][j]&&((i>>(k-1))&1))fl=0;
		if(fl)z1[i^(1<<(j-1))]=(z1[i^(1<<(j-1))]+z1[i])%mod;
	}
	for(int i=0;i<(1<<n);++i)ct[i]=__builtin_ctz(i);
	for(int i=0;i<=n;++i)jb.a[i]=i,bj.a[i]=1;
	int ans=0;
	h[0]=bj;
	for(int i=1;i<(1<<n);++i)for(int j=i;j;j=(j-1)&i){
		if(!(mb[j]&(i^j))&&!(mb[i^j]&j)&&ct[j]==ct[i]){
			h[i]=h[i]-h[i^j]*(z1[j]*jb);
		}
	}
	f[0]=bj;
	for(int i=1;i<(1<<n);++i){
		for(int j=i;j;j=(j-1)&i){
			if(!(mb[i^j]&j))f[i]=f[i]-h[j]*f[i^j];
		}
	}
	for(int i=0;i<=n;++i)y[i]=f[(1<<n)-1].a[i];
	for(int i=0;i<=n;++i){
		int cj=y[i];
		for(int j=0;j<=n;++j)a2[j]=0;
		a2[0]=1;
		int ss=0;
		for(int j=0;j<=n;++j)if(j!=i){
			cj=1ll*cj*powdv(i-j+mod)%mod;
			for(int k=ss;k>=0;--k){
				a2[k+1]=(a2[k+1]+a2[k])%mod;
				a2[k]=1ll*(mod-j)*a2[k]%mod;
			}
			++ss;
		}
		for(int j=0;j<=n;++j)a1[j]=(a1[j]+1ll*cj*a2[j])%mod;
	}
	for(int i=0;i<n&&i<=k;++i){
		ans=(ans+1ll*di[i+1]*a1[i+1]%mod*gl[i])%mod;
	}
	int nj=1;
	for(int i=1;i<=n;++i)nj=1ll*nj*i%mod;
	ans=1ll*ans*powdv(nj)%mod;
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 5900kb

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

score: 5
Accepted
time: 1ms
memory: 5896kb

input:

5 7 5
1 4
2 3
1 2
4 5
2 5
2 4
1 5

output:

895039689

result:

ok single line: '895039689'

Test #3:

score: 5
Accepted
time: 60ms
memory: 8516kb

input:

13 12 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

76923078

result:

ok single line: '76923078'

Test #4:

score: 5
Accepted
time: 178ms
memory: 7712kb

input:

14 13 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14

output:

535714290

result:

ok single line: '535714290'

Test #5:

score: 5
Accepted
time: 81ms
memory: 7604kb

input:

14 13 0
2 9
1 2
1 3
3 8
6 11
2 7
1 5
5 12
2 13
3 14
3 10
3 6
2 4

output:

700595243

result:

ok single line: '700595243'

Test #6:

score: 5
Accepted
time: 68ms
memory: 7712kb

input:

14 13 14
9 11
2 9
5 10
4 6
10 13
2 3
2 7
4 12
2 4
3 8
7 14
3 5
1 2

output:

465070080

result:

ok single line: '465070080'

Test #7:

score: 5
Accepted
time: 108ms
memory: 8624kb

input:

13 0 13

output:

1

result:

ok single line: '1'

Test #8:

score: 5
Accepted
time: 27ms
memory: 7708kb

input:

14 91 14
3 4
2 10
3 10
1 13
6 8
5 6
10 13
7 8
4 9
4 7
3 7
13 14
2 12
1 3
6 9
9 14
1 10
2 9
7 11
9 11
3 12
8 10
4 13
5 9
11 12
5 14
8 12
8 13
5 13
1 5
6 11
9 13
2 5
1 14
7 14
4 14
3 5
5 11
6 12
1 2
7 10
1 4
1 8
6 10
3 8
6 13
10 14
7 12
10 11
2 13
8 11
11 13
6 7
10 12
3 14
4 5
1 6
2 14
5 10
8 14
4 8
1...

output:

4362623

result:

ok single line: '4362623'

Test #9:

score: 5
Accepted
time: 0ms
memory: 8044kb

input:

9 15 9
1 2
3 5
2 8
4 8
1 4
2 5
2 7
4 5
1 9
6 8
6 9
1 3
3 7
5 9
5 8

output:

426526937

result:

ok single line: '426526937'

Test #10:

score: 5
Accepted
time: 2ms
memory: 7952kb

input:

9 14 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
4 5
6 8
4 7
6 7
3 8
4 6

output:

214820829

result:

ok single line: '214820829'

Test #11:

score: 5
Accepted
time: 10ms
memory: 6880kb

input:

13 68 0
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
6 7
6 8
6 9
6 10
6 11
6 12
6 13
7 8
7 10
7 11
7 12
7 13
8 13
9 10
9 11
9 12
9 13...

output:

65784302

result:

ok single line: '65784302'

Test #12:

score: 5
Accepted
time: 15ms
memory: 7000kb

input:

13 39 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 8
4 9
4 10
4 12
4 13
5 6
5 7
5 10
5 11
5 13
6 7
6 11
6 13
8 9
8 12
8 13
11 13

output:

361557272

result:

ok single line: '361557272'

Test #13:

score: 5
Accepted
time: 103ms
memory: 9160kb

input:

14 11 14
2 13
4 11
4 14
5 14
6 9
6 14
7 11
9 14
10 12
10 14
12 14

output:

696132576

result:

ok single line: '696132576'

Test #14:

score: 5
Accepted
time: 26ms
memory: 7700kb

input:

14 46 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 9
2 10
2 11
2 13
2 14
3 4
3 6
3 10
3 11
3 12
3 13
3 14
4 6
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 9
5 11
5 13
5 14
7 8
7 9
7 14
10 11
10 13
10 14
11 13
11 14
13 14

output:

258614192

result:

ok single line: '258614192'

Test #15:

score: 5
Accepted
time: 21ms
memory: 7876kb

input:

14 70 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
3 11
3 13
3 14
4 5
4 7
4 8
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 10
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 10
7 12
7 13
7 14
8 10
8 12
8 13
8 14
9 11
9 12
9 13
9 14
10 1...

output:

209616080

result:

ok single line: '209616080'

Test #16:

score: 5
Accepted
time: 25ms
memory: 7832kb

input:

14 69 14
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 5
2 6
2 7
2 9
2 10
2 11
2 12
2 13
2 14
3 5
3 6
3 7
3 9
3 10
3 11
3 12
3 13
3 14
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
5 6
5 7
5 9
5 10
5 11
5 12
5 13
5 14
6 7
6 9
6 10
6 11
6 12
6 13
6 14
7 9
7 10
7 11
7 12
7 13
7 14
8 12
8 13
8 14
9 10
...

output:

701202127

result:

ok single line: '701202127'

Test #17:

score: 5
Accepted
time: 136ms
memory: 7684kb

input:

14 15 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
4 6
5 9

output:

263013541

result:

ok single line: '263013541'

Test #18:

score: 5
Accepted
time: 384ms
memory: 9420kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
3 13
3 15
13 15

output:

963180835

result:

ok single line: '963180835'

Test #19:

score: 5
Accepted
time: 309ms
memory: 9268kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 12
1 15
7 12
7 15
8 15
9 15
10 15
11 15
12 15
13 15
14 15

output:

722208430

result:

ok single line: '722208430'

Test #20:

score: 5
Accepted
time: 367ms
memory: 9432kb

input:

15 16 15
1 2
1 3
1 10
2 10
3 10
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15

output:

560801339

result:

ok single line: '560801339'