ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213630 | #2715. 8.4t4 | 18112606231 | 70 | 761ms | 138556kb | C++11 | 1.8kb | 2024-11-12 22:08:16 | 2024-11-12 23:59:01 |
answer
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int n, u, v, dp[5001][5001], dpp[5001], C[5001][5001], sz[5001], pos, head[10001];
struct edge
{
int u, v, next;
} e[10001];
void addedge(int u, int v)
{
e[++pos] = {u, v, head[u]};
head[u] = pos;
}
void dfs(int u, int fa)
{
dp[u][1] = 1;
sz[u] = 1;
for (int i = head[u]; i; i = e[i].next)
{
int v = e[i].v;
if (v == fa)
continue;
dfs(v, u);
for (int j = 1; j <= sz[u]; j++)
{
if (dp[u][j])
{
for (int k = j; k <= j + sz[v]; k++)
{
dpp[k] = (dpp[k] + ((dp[u][j] * dp[v][k - j] % MOD) * C[k - 1][j - 1] % MOD)) % MOD;
}
}
}
sz[u] += sz[v];
for (int j = 1; j <= sz[u]; j++)
{
dp[u][j] = dpp[j];
dpp[j] = 0;
}
}
for (int j = sz[u]; j >= 0; j--)
{
dp[u][j] = (dp[u][j] + dp[u][j + 1]) % MOD;
}
}
signed main()
{
n = read();
for (int i = 1; i < n; i++)
{
u = read();
v = read();
addedge(u, v);
addedge(v, u);
}
C[0][0] = 1;
for (int i = 1; i <= n; i++)
{
C[i][0] = 1;
for (int j = 1; j <= i; j++)
{
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
}
dfs(1, 0);
printf("%lld\n", dp[1][0] % MOD);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
10 1 2 1 3 3 4 3 5 3 6 3 7 1 8 5 9 5 10
output:
227506
result:
ok found '227506.00000', expected '227506.00000', error '0.00000'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
10 1 2 1 3 3 4 4 5 5 6 4 7 5 8 8 9 8 10
output:
70140
result:
ok found '70140.00000', expected '70140.00000', error '0.00000'
Test #3:
score: 10
Accepted
time: 0ms
memory: 2020kb
input:
100 1 2 1 3 1 4 3 5 5 6 4 7 7 8 8 9 8 10 3 11 7 12 1 13 5 14 8 15 10 16 7 17 1 18 6 19 10 20 15 21 7...
output:
875072841
result:
ok found '875072841.00000', expected '875072841.00000', error '0.00000'
Test #4:
score: 10
Accepted
time: 0ms
memory: 2020kb
input:
100 1 2 2 3 3 4 4 5 4 6 6 7 5 8 8 9 8 10 1 11 6 12 4 13 9 14 13 15 7 16 3 17 15 18 17 19 9 20 8 21 4...
output:
706867541
result:
ok found '706867541.00000', expected '706867541.00000', error '0.00000'
Test #5:
score: 10
Accepted
time: 0ms
memory: 2024kb
input:
100 1 2 2 3 3 4 2 5 2 6 5 7 2 8 4 9 7 10 5 11 11 12 6 13 8 14 13 15 5 16 11 17 16 18 11 19 7 20 19 2...
output:
515055734
result:
ok found '515055734.00000', expected '515055734.00000', error '0.00000'
Test #6:
score: 10
Accepted
time: 0ms
memory: 6220kb
input:
500 1 2 1 3 3 4 3 5 5 6 1 7 3 8 8 9 4 10 6 11 7 12 2 13 11 14 8 15 7 16 9 17 2 18 3 19 15 20 2 21 20...
output:
28964814
result:
ok found '28964814.00000', expected '28964814.00000', error '0.00000'
Test #7:
score: 10
Accepted
time: 4ms
memory: 6200kb
input:
500 1 2 1 3 1 4 2 5 5 6 5 7 4 8 8 9 1 10 4 11 8 12 6 13 13 14 13 15 12 16 1 17 10 18 13 19 1 20 1 21...
output:
900482908
result:
ok found '900482908.00000', expected '900482908.00000', error '0.00000'
Test #8:
score: 0
Wrong Answer
time: 216ms
memory: 138548kb
input:
5000 1 2 1 3 1 4 3 5 3 6 5 7 4 8 4 9 1 10 5 11 6 12 10 13 12 14 14 15 12 16 8 17 14 18 9 19 8 20 20 ...
output:
96015670
result:
wrong answer 1st numbers differ - expected: '255910011.00000', found: '96015670.00000', error = '0.6...
Test #9:
score: 0
Wrong Answer
time: 226ms
memory: 138556kb
input:
5000 1 2 1 3 1 4 2 5 1 6 5 7 2 8 5 9 4 10 9 11 10 12 8 13 7 14 13 15 12 16 5 17 9 18 8 19 3 20 4 21 ...
output:
608935665
result:
wrong answer 1st numbers differ - expected: '506490313.00000', found: '608935665.00000', error = '0....
Test #10:
score: 0
Wrong Answer
time: 315ms
memory: 138488kb
input:
5000 1 2 1 3 1 4 4 5 4 6 3 7 2 8 8 9 6 10 9 11 3 12 3 13 7 14 13 15 4 16 10 17 9 18 10 19 5 20 17 21...
output:
34752823
result:
wrong answer 1st numbers differ - expected: '738067707.00000', found: '34752823.00000', error = '0.9...