P7075
P3799
P7915
P1462
P2824
P1198
#include <bits/stdc++.h>
using namespace std;
int main()
{
int ans = 0;
for (int k = 30; k >= 0; --k)
{
if (ans + (1 << k) <= n && check (ans + (1 << k)) == 1) ans += (1 << k);
}
return 0;
}P1908
AT_agc055_b
P1650
P1080
AT_abc366_f
CF021D
P1248
AT_agc023_f
P7514
线段树: 单点修改,区间查询
懒标记
struct Info { ll IOI, I, O, OI, IO; };
struct node { ll l, r; Info d; }tree[N << 2];
inline Info init(char ch) { return (ch == 'I') ? (Info){0, 1, 0, 0, 0} : (Info){0, 0, 1, 0, 0}; }
Info operator + (Info pol_1, Info pol_2)
图论
最短路:佛洛依德算法,贝尔曼福特,迪杰斯特拉
贝尔曼福特:判断负环,松弛操作
差分约束:多元一次不等式,通过移项得到,对新构造的图,跑最短路,跑出来就说明有解,否则就无解。
DP
树形DP:给一棵无根树,树形DP通常先选一个根(常选1号点)。
DFS后,对每个结点的子树进行遍历
转移方程,状态一般写成: 只和 u 的子树有关。
树上背包DP
换根DP:选每一个根中的最优答案
选课,没有上司约会,LCA,拓扑排序,最大食物链数量。
和表示这个上司是否参加舞会
拓扑排序:记录每一个节点的入度,为零即进队,作为候选答案,一直循环
//你看, 這世界开滿了花。
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
constexpr int N = 600 + 10;
LL n, in_degree[N];
std::vector<LL> edge[N];
std::queue<LL> cur;
inline LL read()
{
LL f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
while (c <= '9' && c >= '0') { x= (x << 1) + (x << 3) + (c ^ '0'); c = getchar(); }
return f * x;
}
inline void solve()
{
while (!cur.empty())
{
auto pre = cur.front(); cur.pop();
std::cout << pre << '\n';
for (auto t : edge[pre])
{
in_degree[t]--;
if (!in_degree[t]) cur.push(t);
}
}
return ;
}
int main()
{
n = read();
for (int i = 1; i <= n; ++i)
{
LL v; v = read();
while (v != 0) { edge[i].pb(v); in_degree[v]++; v = read(); }
}
for (int i = 1; i <= n; ++i)
if (!in_degree[i]) cur.push(i);
solve();
return 0;
}差分约束:不会