QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103275 | #5367. 递增树列 | zhouhuanyi | 0 | 0ms | 3612kb | C++11 | 2.8kb | 2023-05-04 22:52:19 | 2023-05-04 22:52:22 |
Judging History
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][0]=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=0;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;++s2)
for (int t2=s2;t2<=sz[p[k-1]]-j;++t2)
Adder(DP[k][s+s2][t+t2],1ll*DP[k-1][s][t]*C[sz[p[k-1]]-j][t2]%mod*C[t2-1][s2-1]%mod*invfac[s2-1]%mod*fac[t2]%mod);
}
res+=sz[p[k-1]]-j;
}
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],1ll*dp[p[i-1]][j]*DP[p.size()][s][t]%mod*fac[s-1]%mod);
else Adder2(dsp[t+j],-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) Adder(dp[x][i],dsp[i]);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3612kb
input:
7 1 2 2 3 2 4 1 5 5 6 3 7
output:
760
result:
wrong answer 1st lines differ - expected: '712', found: '760'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%