标签:space bsp style tar include lse return oid code
树形dp
f[i][j] - 到i号点,已经j时间了的最大偷画数
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for(int i = a; i <= b; ++i) const int N = 107; const int S = 607; int s, n, f[N][S]; void dfs(int u) { int time, paint; scanf("%d%d", &time, &paint); if (!paint) { int L = ++n, r = ++n; dfs(L), dfs(r); rep(i, time * 2 + 1, s - 1) rep(j, 0, i - time * 2) { f[u][i] = max(f[u][i], f[L][j] + f[r][i - j - time * 2]); } } else { rep(i, time * 2 + 1, s - 1) { f[u][i] = min((i - time * 2) / 5, paint); } } } int main() { scanf("%d", &s); dfs(0); printf("%d\n", f[0][s - 1]); //注意读题 警察在s秒抓到他,所以他必须最迟在s - 1秒中时结束 return 0; }
标签:space bsp style tar include lse return oid code
原文地址:https://www.cnblogs.com/Fo0o0ol/p/10023343.html