for (int i = 1; i <= 4; i++) { x[i] = x[i - 1] + read(); } for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + read(); }
int ans = 0; for (int i = 1; i <= n; i++) { for (int a = 0; a <= n / 2 + 1; a++) { for (int b = 0; b <= n / 3 + 1; b++) { for (int c = 0; c <= n / 4 + 1; c++) { for (int d = 0; d <= n / 5 + 1; d++) { if (a * x[1] + b * x[2] + c * x[3] + d * x[4] > T) break;
int res = dp[(i + 5) % 6][a][b][c][d]; if (a >= 1and i >= 1) res = max(res, dp[(i + 4) % 6][a - 1][b][c][d] + s[i] - s[i - 1]); if (b >= 1and i >= 2) res = max(res, dp[(i + 3) % 6][a][b - 1][c][d] + s[i] - s[i - 2]); if (c >= 1and i >= 3) res = max(res, dp[(i + 2) % 6][a][b][c - 1][d] + s[i] - s[i - 3]); if (d >= 1and i >= 4) res = max(res, dp[(i + 1) % 6][a][b][c][d - 1] + s[i] - s[i - 4]);
voidsolve(){ int n = read(), q = read(); string s; cin >> s; s = " " + s;
int las = -1; vector<int> sum(n + 5), pre(n + 5), suf(n + 5); for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1]; if (s[i] == '1'and las != i - 1) { sum[i]++, las = i; } }
for (int i = 1; i <= n; i++) { if (s[i] == '1') { suf[i] = suf[i - 1] + 1; } else { suf[i] = 0; } } for (int i = n; i >= 1; i--) { if (s[i] == '1') { pre[i] = pre[i + 1] + 1; } else { pre[i] = 0; } }
while (q--) { int l = read(), r = read(); auto calc = [&]() -> int { int ll = l + pre[l], rr = r - suf[r]; if (ll >= rr) return (r - l + 1 + 1) / 2; return sum[rr] - sum[ll - 1] + (pre[l] + suf[r] + 1) / 2; }; int res = max(0LL, (r - l + 1) / 3 - calc()); cout << res << '\n'; } }
Z go(){ Z res = 0; while (1) { string s; cin >> s; if (s == "for") { break; } elseif (s == "library") { res += 1; } elseif (s == "repeat") { res += go(); } } int coef; cin >> coef; return coef * res; }
voidsolve(){ Z ans = 0; while (1) { string s; cin >> s; if (s == "fin") { break; } elseif (s == "library") { ans += 1; } elseif (s == "repeat") { ans += go(); } }
cout << ans << '\n'; }
C - Delete the Tree
把整棵树删完等价于整张图 0 / 1 度点总数量为 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
voidsolve(){ int n = read();
vector<vector<int>> g(n + 1); for (int i = 1; i < n; i++) { int u = read(); int v = read(); g[u].eb(v); g[v].eb(u); }
int ans = 0; for (int i = 1; i <= n; i++) { if (g[i].size() <= 1) ans++; } cout << ans << '\n'; }