QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103320#5367. 递增树列zhouhuanyi20 3ms3700kbC++112.9kb2023-05-05 10:23:042023-05-05 10:23:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-05 10:23:05]
  • 评测
  • 测评结果:20
  • 用时:3ms
  • 内存:3700kb
  • [2023-05-05 10:23:04]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 80
#define mod 1000000007
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
int MD(int x)
{
    return x>=mod?x-mod:x;
}
void Adder(int &x,int d)
{
    x+=d;
    if (x>=mod) x-=mod;
    return;
}
void Adder2(int &x,int d)
{
    x+=d;
    if (x<0) x+=mod;
    return;
}
int fast_pow(int a,int b)
{
    int res=1,mul=a;
    while (b)
    {
	if (b&1) res=1ll*res*mul%mod;
	mul=1ll*mul*mul%mod,b>>=1;
    }
    return res;
}
int n,ans,sz[N+1],fac[N+1],invfac[N+1],C[N+1][N+1],dp[N+1][N+1],dsp[N+1],DP[N+1][N+1][N+1];
bool used[N+1];
vector<int>E[N+1];
void add(int x,int y)
{
    E[x].push_back(y),E[y].push_back(x);
    return;
}
void dfs(int x)
{
    int res,rst=1;
    vector<int>p;
    used[x]=sz[x]=dp[x][1]=1;
    for (int i=0;i<E[x].size();++i)
	if (!used[E[x][i]])
	    dfs(E[x][i]),p.push_back(E[x][i]),rst+=sz[E[x][i]];
    p.push_back(x);
    for (int i=0;i<=rst;++i) dsp[i]=0;
    for (int i=1;i<=p.size();++i)
	for (int j=1;j<=sz[p[i-1]];++j)
	{
	    res=0;
	    for (int k=0;k<=p.size();++k)
		for (int s=0;s<=rst;++s)
		    for (int t=0;t<=rst;++t)
			DP[k][s][t]=0;
	    DP[0][0][0]=1;
	    for (int k=1;k<=p.size();++k)
	    {
		if (k==i)
		{
		    for (int s=0;s<=res;++s)
			for (int t=s;t<=res;++t)
			{
			    for (int s2=1;s2<=sz[p[k-1]]-(j-1);++s2)
				for (int t2=s2;t2<=sz[p[k-1]]-(j-1);++t2)
				    Adder(DP[k][s+s2][t+t2],1ll*DP[k-1][s][t]*C[sz[p[k-1]]-j][t2-1]%mod*C[t2-1][s2-1]%mod*invfac[s2-1]%mod*fac[t2-1]%mod);
			}
		    res+=sz[p[k-1]]-(j-1);
		}
		else
		{
		    for (int s=0;s<=res;++s)
			for (int t=s;t<=res;++t)
			{
			    for (int s2=1;s2<=sz[p[k-1]];++s2)
				for (int t2=s2;t2<=sz[p[k-1]];++t2)
				    Adder(DP[k][s+s2][t+t2],1ll*DP[k-1][s][t]*C[sz[p[k-1]]][t2]%mod*C[t2-1][s2-1]%mod*invfac[s2]%mod*fac[t2]%mod);
			    Adder(DP[k][s][t],DP[k-1][s][t]);
			}
		    res+=sz[p[k-1]];
		}
	    }
	    for (int s=1;s<=res;++s)
		for (int t=s;t<=res;++t)
		{
		    if (!((t-s)&1)) Adder(dsp[t+j-1],1ll*dp[p[i-1]][j]*DP[p.size()][s][t]%mod*fac[s-1]%mod);
		    else Adder2(dsp[t+j-1],-1ll*dp[p[i-1]][j]*DP[p.size()][s][t]*fac[s-1]%mod);
		}
	}
    sz[x]=rst;
    for (int i=0;i<=rst;++i) dp[x][i]=dsp[i];
    dp[x][0]=1;
    return;
}
int main()
{
    int x,y;
    fac[0]=1;
    for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
    invfac[N]=fast_pow(fac[N],mod-2);
    for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
    for (int i=0;i<=N;++i) C[i][0]=1;
    for (int i=1;i<=N;++i)
	for (int j=1;j<=i;++j)
	    C[i][j]=MD(C[i-1][j-1]+C[i-1][j]);
    n=read();
    for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
    dfs(1),printf("%d\n",dp[1][n]);
    return 0;
}

详细

Subtask #1:

score: 9
Accepted

Test #1:

score: 9
Accepted
time: 0ms
memory: 3516kb

input:

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

output:

712

result:

ok single line: '712'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

5
1 2
1 3
3 4
4 5

output:

44

result:

ok single line: '44'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

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

output:

576

result:

ok single line: '576'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3584kb

input:

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

output:

6912

result:

ok single line: '6912'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

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

output:

3360

result:

ok single line: '3360'

Subtask #2:

score: 11
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 11
Accepted
time: 2ms
memory: 3672kb

input:

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

output:

389151297

result:

ok single line: '389151297'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3628kb

input:

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

output:

17381952

result:

ok single line: '17381952'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

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

output:

4993920

result:

ok single line: '4993920'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

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

output:

818474475

result:

ok single line: '818474475'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

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

output:

16041048

result:

ok single line: '16041048'

Subtask #3:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 0
Wrong Answer
time: 3ms
memory: 3632kb

input:

25
1 2
1 3
3 4
4 5
2 6
2 7
5 8
5 9
1 10
10 11
9 12
5 13
4 14
12 15
1 16
14 17
2 18
2 19
16 20
18 21
18 22
20 23
17 24
19 25

output:

943564378

result:

wrong answer 1st lines differ - expected: '179142361', found: '943564378'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%