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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
有赞技术团队
有赞技术团队
Jina AI
Jina AI
GbyAI
GbyAI

某岛

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: 日常