#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std; //东方之ç æ•´å¤œæœªçœ ï¼? constint M = 1e5+66;
int f[M], a[M], d[M], v[M], c[M];
int n, X, Y, N, flag;
inlinevoiddfs(int x, int k) { if (flag) return; if (k == N) { memset(f, 0, sizeof f); memset(d, 0, sizeof d); intres1(0), res2(0), i, j; for (i = 1; i <= n; ++ i) { f[i] = d[i] = 1;; for (j = 1; j < i; ++ j) { if (a[j] < a[i]) f[i] = max(f[j]+1, f[i]); if (a[j] > a[i]) d[i] = max(d[j]+1, d[i]); } } for (i = 1; i <= n; ++ i) { res1 = max(res1, f[i]); res2 = max(res2, d[i]); } if (res1 == X && res2 == Y) { for (i = 1; i <= n; ++ i) c[i] = a[i]; flag = 1; return ; } return; } for (int i = 1; i <= n; ++ i) { if (v[i]) continue; v[i] = 1; a[++ k] = i; dfs(i + 1, k); v[i] = 0; -- k; } }
inlinevoidwork() { dfs(1, 0); if (flag) { puts("YES"); for (int i = 1; i <= n; ++ i) cout << c[i] << ' '; } elseputs("NO"); }
inlineintthestars() { int i, j, k, n, x, y, m, res(0); scanf ("%d%d%d", &n, &x, &y); if (n <= 7) { N = n, X = x, Y = y; work(); return0; } m = n, k = (n - y + 1); for (i = k; i <= n; ++ i) a[i] = (m --); if (k == x) { puts("YES"); for (i = 1; i < k; ++ i) cout << i << ' '; for (i = k; i <= n; ++ i) cout << a[i] << ' '; return0; } if (k < x) {puts("NO");return0;} int maxh = k - 1; j = maxh; int cha = k - x; int yhm = cha + 1; if (yhm > y) {puts("NO");return0;} j -= cha; puts("YES"); for (i = 1; i < j; ++ i) cout << i << ' '; for (i = maxh; i >= j; -- i) cout << i << ' '; for (i = k; i <= n; ++ i) cout << a[i] << ' '; return0; }
inline LL ksm(LL a, LL b) { LL res(1); for (; b; b >>= 1) { if (b&1) res = res * a; a = a * a; } return res; }
priority_queue<pr, vector<pr>, greater<pr> >q; int v[N]; LL dis[N];
inlinevoiddij(int s) { int i, x, y; LL z; memset(v, 0, sizeof v); memset(dis, 0x3f, sizeof dis); dis[s] = 0, q.push(make_pair(0, s)); while (q.size()) { z = q.top().first, x = q.top().second; q.pop(); if (v[x]) continue; v[x] = 1; for (i = head[x]; i; i = nex[i]) { y = to[i]; if (dis[y] > z + len[i]) { dis[y] = z + len[i]; if (! v[y]) { q.push(pr(dis[y], y)); } } } } }
int a[N];
inline LL thestars() { int i, x, y, n, m; LL z, res(0); scanf ("%d%d", &n, &m); for (i = 1; i <= n; ++ i) scanf ("%d", a + i); for (i = 1; i <= m; ++ i) { scanf ("%d%d", &x, &y); z = ksm(2, i); add(x, y, z); add(y, x, z); } for (x = 1; x <= n; ++ x) { dij(x); for (i = x + 1; i <= n; ++ i) { // if (i == x) continue; // if (x == 2 && y == 3) cout << "herre\n"; // if (i < x || a[x] == a[i]) continue; if (a[x] == a[i]) continue; res = (res + dis[i])%mod; #ifdef debug cout << "x===>" <<x << " i---->" << i << " len[i]---->" << dis[i] << '\n'; #endif } } cout << res%mod; return0; }