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

推荐订阅源

爱范儿
爱范儿
量子位
人人都是产品经理
人人都是产品经理
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Recent Announcements
Recent Announcements
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
H
Help Net Security
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
The Cloudflare Blog
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
Vercel News
Vercel News

某岛

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] 切糕
2023-06-07 · via 某岛

June 7, 2023

简单最小割~

#include <lastweapon/io>
#include <lastweapon/maxflow>

using namespace lastweapon;

int P, Q, R, D, s, t;

int id(int p, int q, int r) {
    return r*P*Q + p*Q + q;
}

bool inGrid(int p, int q) {
    return 0 <= p && p < P && 0 <= q && q < Q;
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout);
#endif

    RD(P, Q, R, D); s = P*Q*R, t = s+1;
    mf_graph<int> G(t+1);


    REP(p, P) REP(q, Q) {
        G.add_edge(s, id(p, q, 0), INF);
    }

    REP(r, R) REP(p, P) REP(q, Q) {
        int u = id(p, q, r);
        G.add_edge(u, r+1 != R ? id(p, q, r+1) : t, RD());
        if (r >= D) {
            REP(i, 4) {
                int x = p + dx[i], y = q + dy[i];
                if (!inGrid(x, y)) continue;
                int v = id(x, y, r-D);
                G.add_edge(u, v, INF);
            }
        }
    }

    cout << G.flow(s, t) << endl;
}

Posted by xiaodao
Category: 日常