惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
AI
AI
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
V2EX - 技术
V2EX - 技术
www.infosecurity-magazine.com
www.infosecurity-magazine.com
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
O
OpenAI News
Scott Helme
Scott Helme
C
Cisco Blogs
雷峰网
雷峰网
H
Help Net Security
P
Palo Alto Networks Blog
MyScale Blog
MyScale Blog
I
Intezer
Security Latest
Security Latest
N
News | PayPal Newsroom
美团技术团队
N
News and Events Feed by Topic
B
Blog RSS Feed
T
Tor Project blog
小众软件
小众软件
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
U
Unit 42
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog
K
Kaspersky official blog
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
P
Privacy International News Feed

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔 Luogu P3227. [HNOI2013] 切糕 Luogu P8500. [NOI2022] 冒泡排序 Luogu P3629. [APIO2010] 巡逻 USACO 2018 February Contest, Gold Problem 2. Directory Traversal Luogu P3647. [APIO2014] 连珠线 IZhO 2017. Problem F. Hard route SPOJ TWOPATHS. Two Paths 换根 dp 洪恩电脑 —— 开天辟地 Facebook Hacker Cup 2022 Round 2 Codeforces Round #875 Luogu P5828 边双连通图计数 EC Final 拉格朗日反演定理 Luogu P5827. 点双连通图计数 无标号连通图 AtCoder Beginner Contest 284 Luogu P4708. 画画 Luogu P6295. 有标号 DAG 计数 BZOJ #2863. 愤怒的元首 HDU 3303. Harmony Forever 聊聊《明日方舟 Side Story 孤星》与《崩坏:星穹铁道》 SGU 208. Toral Tickets 后日谈,SHLUG 月度分享(上) 钢琴练习 EasyRPG x ChatGPT ControlNet 相关 The 1st Universal Cup, Stage 4, Ukraine EasyRPG —— Sliding Puzzle The 1st Universal Cup, Stage 3, Poland DP 优化练习 NOI 2009 TypeDB Forces 2023 Nas 买来做什么… Global Game Jam 2023 参赛纪录 The 1st Universal Cup, Stage 2, Hongkong The 1st Universal Cup, Stage 0, Nanjing Codeforces Round #850 舟游同人游戏 RM2k3 机能增强 —— EasyRPG Player 魔改版 《海之歌》设定与剧本 dfs 序求 lca Codeforces Round #844 P3768 简单的数学题 AtCoder Beginner Contest 281 ChatGPT 相关 AtCoder Grand Contest 059 AtCoder Beginner Contest 280 Codeforces Global Round 24 事实核查,以乌鲁木齐火灾为例 SPOJ MUSKET. Musketeers Pinely Round 1 Note about FTX Permutation ICPC World Final 2021 CodeTON Round 3 Codeforces Round #831 Educational Codeforces Round 138 NovelAI 法术指南 卡农 Educational Codeforces Round 135 Codeforces Round #819 瓦喵之夏 NOI 2022 Luogu P3765 总统选举 Luogu P3369 【模板】普通平衡树 网络国家 旋转卡壳 OFAC Sanctions && Tornado Cash BZOJ 1185. [HNOI2007]最小矩形覆盖
树形背包
2021-09-19 · via 某岛

暴力枚举 O(n3)

const int M = int(3e2) + 9;
const int N = int(3e2) + 9;
int dp[N][M], cost[N], value[N]; VI adj[N];
int n, m;

void dfs(int u = 0) {
    FLC(dp[u], 0x80);
    DWN_1(i, m, cost[u]) dp[u][i] = value[u];

    for (auto v: adj[u]) {
        dfs(v);
        DWN_1(i, m, cost[u]) {
            FOR_1(j, cost[u], i) {
                checkMax(dp[u][i], dp[u][j] + dp[v][i-j]);
            }
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout);
#endif
    RD(n, m);
    REP_1(i, n) {
        int p; RD(p, value[i]); cost[i] = 1;
        adj[p].push_back(i);
    }
    dfs();
    cout << dp[0][m] << endl;
}

状态继承 O(n2)

const int N = int(1e5) + 9;
const int M = int(1e5) + 9;
int cost[N], value[N]; VI adj[N];
int n, m;

void dfs(int u, int m, VI& dpu) {
    m -= cost[u];
    for (auto v: adj[u]) {
        VI dpv = dpu; dfs(v, m, dpv);
        FOR_1(i, 0, m) checkMax(dpu[i], dpv[i]);
    }
    m += cost[u];
    DWN_1(i, m, cost[u]) dpu[i] = dpu[i-cost[u]] + value[u];
    REP(i, cost[u]) dpu[i] = -INF;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout);
#endif
    RD(n, m);
    REP_1(i, n) {
        int p; RD(p, value[i]); cost[i] = 1;
        adj[p].push_back(i);
    }
    VI dp0; dp0.resize(m+1);
    dfs(0, m, dp0);
    cout << dp0[m] << endl;
}

P1273 有线电视网
https://www.luogu.com.cn/problem/P1273


const int N = (3e3) + 9;
VII adj[N]; int sz[N];
int dp[N][N], bonus[N];
int n, m, z;

bool isLeaf(int u) {
    return u > n-m;
}

void dfs0(int u) {
    sz[u] = isLeaf(u);
    for (auto e: adj[u]) {
        int v = e.fi;
        dfs0(v);
        sz[u] += sz[v];
    }
}

void dfs(int u) {
    FLC(dp[u], 0x80);
    dp[u][0] = 0;

    if (isLeaf(u)) {
        dp[u][1] = bonus[u];
        return;
    }

    for (auto e: adj[u]) {
        int v = e.fi, w = e.se;
        dfs(v);
        DWN_1(i, sz[u], 1) {
            REP_1(j, sz[v]) {
                checkMax(dp[u][i], dp[u][i-j] + dp[v][j] - w);
            }
        }
    }
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout);
#endif
    RD(n, m); REP_1(u, n-m) {
        Rush {
            int v, c; RD(v, c);
            adj[u].PB({v,c});
        }
    }

    FOR_1(u, n-m+1, n) RD(bonus[u]);

    dfs0(1); dfs(1);
    DWN_1(i, m, 0) {
        if (dp[1][i] >= 0) {
            cout << i << endl;
            return 0;
        }
    }
}

道路重建

https://www.luogu.com.cn/problem/P1272
https://www.luogu.com.cn/problem/U53878


const int N = (1e5) + 9;
VI adj[N]; int sz[N];
int n, m, z;

VI dp[N];
// dp[u][i],保留 u 节点同时子树再保留 i 个节点的子树,最少删多少边

void dfs(int u, int p){

    sz[u] = 1; dp[u].PB(0);

    for (auto v: adj[u]) if (v != p) {
        dfs(v, u);

        REP(i, SZ(dp[u])) dp[u][i] += 1;
        DO(min(sz[v], m+1-sz[u])) dp[u].PB(INF);
        sz[u] += sz[v];

        DWN(i, SZ(dp[u]), 1) {
            REP(j, min(SZ(dp[v]), i)) {
                checkMin(dp[u][i], dp[u][i-1-j] + dp[v][j] - 1);
            }
        }
    }

    if (sz[u] > m) checkMin(z, dp[u][m] + bool(p));
}

signed main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout);
#endif
    RD(n, m); --m; DO(n-1){
        int a, b; RD(a, b);
        adj[a].PB(b);
        adj[b].PB(a);
    }
    z = INF; dfs(1, 0);
    cout << z << endl;
}

Posted by xiaodao
Category: 日常