#include<bits/stdc++.h> #define ll long long usingnamespacestd; constint maxn = 100 + 10; int a[maxn], n;
structEdge { int v, w; }; vector<Edge> g[maxn];
// 循环非递归版 structTrie { staticconstint M = 2; // 字符集大小 staticconstint LEN = 31; int nex[maxn * 30][M], cnt = 0, val[maxn]; // cnt记录点号 int xorv[maxn];
voidins(ll x) { int now = 0; for (int i = LEN; i >= 0; i--) { int c = (x >> i) & 1; if(!nex[now][c]) { nex[now][c] = ++cnt; nex[cnt][0] = nex[cnt][1] = 0; } now = nex[now][c]; } }
voidinit() { nex[0][0] = nex[0][1] = cnt = 0; }
ll find(ll x) { ll now = 0, ret = 0; for (int i = LEN; i >= 0; i--) { int c = (x >> i) & 1; if(nex[now][c]) now = nex[now][c]; else { now = nex[now][c ^ 1]; ret |= (1 << i); } } return ret; } }trie;
ll merge(int m, int l, int r) { if (l == m || m == r) return0; trie.init(); ll ret = 0x3f3f3f3f3f3f3f3f; for (int i = m; i < r; i++) trie.ins(a[i]); for (int i = l; i < m; i++) ret = min(ret, trie.find(a[i])); return ret; }
voiddfs(int u, int fa) { for (int i = 0; i < g[u].size(); i++) { auto e = g[u][i]; if(e.v == fa) continue; a[e.v] = a[u] ^ e.w; // 边权转化为点权 dfs(e.v, u); } }
ll solve(int dep, int l, int r) { if(dep == -1 || l == r) return0; int mid = l; // 找到分叉点,从最高位开始 while(mid < r && ((a[mid] >> dep) & 1) == 0) ++mid; // 找到了最高位为 1 的 ll ret = solve(dep - 1, l, mid) + solve(dep - 1, mid, r); return ret + merge(mid, l, r); }
intmain() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif scanf("%d", &n); int u, v, w; for (int i = 1; i < n; i++) { scanf("%d%d%d", &u, &v, &w); u++, v++; g[u].push_back({v, w}); g[v].push_back({u, w}); } dfs(1, -1); sort(a + 1, a + 1 + n);
int T, n, m, k; get_inv(N - 1, mod); for (int i = 1; i < N; i++) inv[i] = inv[i] * inv[i - 1] % mod; f[0] = 1; for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % mod; scanf("%d", &T); while (T--) { scanf("%d%d%d", &n, &m, &k); ll ans = 0; for (int i = 0; i <= min(n, m) - k; i++) { ans = (ans + C(k + i - 1, k - 1) * C(n - i - 1, k - 1) % mod * C(m - i - 1, k - 1) % mod) % mod; //xy个数x个数y个数 } printf("%lld\n", ans); } }
int n; int a[maxn]; int dp[maxn]; intmain() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = n + 1; i < 2 * n; i++) a[i] = a[i - n];
int ans = 0; for (int k = 1; k <= n; k++) { int end = k + n - 1; int top = 0; dp[++top] = a[k]; for (int i = k + 1; i <= end; i++) { if(a[i] > dp[top]) dp[++top] = a[i]; else { int pos = lower_bound(dp + 1, dp + top, a[i]) - dp; dp[pos] = a[i]; } } ans = max(ans, top); // pos刚好为个数 } printf("%d\n", n - ans); return0; }
int p[N] = {....}; // Tonnnny's favorite permutation of n voidshuffle(int a[], int n){ int b[n]; for (int i = 0; i < n; i++) { b[i] = a[i] } for (int i = 0; i < n; i++) { a[i] = b[p[i]]; } }