QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164379#5367. 递增树列zhaohaikun0 0ms0kbC++143.8kb2023-09-04 22:20:382023-09-04 22:20:38

Judging History

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

  • [2023-09-04 22:20:38]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-09-04 22:20:38]
  • 提交

answer

#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 85, MOD = 1e9 + 7;
int n, sz[N], f[N][N][N], C[N][N], dp[N][N], s[N], h[N][N][N], fac[N], A[N][N], p[N][N];
vector <int> v[N];
void dfs(int x, int fa) {
	for (auto i = v[x].begin(); i != v[x].end(); ++i)
		if (*i == fa) {
			v[x].erase(i);
			break;
		}
	sz[x] = 1;
	for (int i: v[x]) {
		dfs(i, x);
		sz[x] += sz[i];
	}
}
inline void add(int &x, ll y) { x = (x + y) % MOD; }
int g[N][N];
void work(int f[N][N], int x, int y) {
	ms(g, 0);
	g[0][0] = 1;
	// cout << "# " << x << " " << y << endl;
	F(inc, 1, y) g[inc][inc - 1] = A[y][inc];
	F(i, 1, x)
		F(j, 0, i - 1) if (f[i][j]) {
			// choose 0
			add(g[i][j], f[i][j]);
			F(inc, 1, y)
				F(a, 0, min(i - 1, inc))
					F(b, 0, min(a, j)) {
						int k = (ll) f[i][j] * C[i - 1 - j][a - b] % MOD * C[j][b] % MOD;
						// case 1:
						if (a) add(g[i + inc][j - b + inc - 1 - (a - 1)], (ll) k * C[inc - 1][a - 1] % MOD * A[y][inc]);
						// case 2:
						if (a + 1 <= inc) add(g[i + inc][j - b + inc - 1 - a], 2ll * k * C[inc - 1][a] % MOD * A[y][inc]);
						// case 3:
						if (a + 2 <= inc) add(g[i + inc][j - b + inc - 1 - (a + 1)], (ll) k * C[inc - 1][a + 1] % MOD * A[y][inc]);
					}
		}
}
void work2(int f[N][N], int x, int y) {
	ms(p, 0);
	p[0][0] = 1;
	// F(inc, 1, y) p[inc][inc][inc - 1] = (ll) C[y][inc] * fac[inc] % MOD;
	F(i, 1, x)
		F(j, 0, i - 1) if (f[i][j]) {
			// choose 0
			// if (!j) add(p[0][i], f[i][j]);
			F(k, j, y) {
				add(p[k][i + k], (ll) f[i][j] * C[i - j][k - j]);
			}
		}
}
void trans(int x) {
	F(a, 0, s[x])
		F(b, 0, a)
			f[x][a][b] = g[a][b];
}
void transh(int x, int sz) {
	F(a, 0, sz)
		F(b, 0, a)
			h[x][a][b] = g[a][b];
}
void dfs2(int x) {
	for (int i: v[x]) dfs2(i);
	for (int i: v[x]) {
		f[i][0][0] = 1;
		work(f[i], s[i], 1);
		// swap(f[i], g);
		s[i]++;
		trans(i);
		for (int j: v[x])
			if (i != j) {
				work(f[i], s[i], sz[j]);
				// swap(f[i], g);
				s[i] += sz[j];
				trans(i);
			}
	}
	int t = 0;
	h[x][0][0] = 1;
	work(h[x], t, 1);
	// swap(h[x], g);
	t++;
	transh(x, t);
	for (int i: v[x]) {
		work(h[x], t, sz[i]);
		// swap(h[x], g);
		t += sz[i];
		transh(x, t);
	}
	// if (x == 1) cout << h[x][2][1] << endl;
	F(p, 1, sz[x]) dp[x][p] = h[x][p][0];
	// F(i, 1, sz[x]) {
	// 	F(j, 0, i - 1)
	// 		cout << x << " " << i << " " << j << " " << h[x][i][j] << endl;
	// }
	for (int i: v[x]) {
		work2(f[i], s[i], sz[i]);
		F(q, 2, sz[i]) {
			int k = sz[i] - q;
			F(p, q, sz[x]) {
				int s = 0;
				F(j, 0, k) add(s, (ll) ::p[j][p - q] * A[k][j]);
				add(dp[x][p], (ll) dp[i][q] * s);
			}
		}
	}
	// F(i, 1, sz[x]) cout << x << " " << i << " " << dp[x][i] << endl;
}
signed main() {
	freopen("seq.in", "r", stdin);
	freopen("seq.out", "w", stdout);
	read(n);
	fac[0] = 1;
	F(i, 1, n) fac[i] = (ll) i * fac[i - 1] % MOD;
	F(i, 0, n) {
		A[i][0] = C[i][0] = 1;
		F(j, 1, i) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD, A[i][j] = (ll) C[i][j] * fac[j] % MOD;
	}
	F(i, 2, n) {
		int x, y; read(x), read(y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, 0);
	dfs2(1);
	cout << dp[1][n];
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

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

output:


result:


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%