A层邀请赛6

题挺水的,好几个AK的,但是我爆零了

A. 菜

我就是菜。

读题读错,没发现他只能走一个来回,还写爆力拍,我有大病吧

就是一个傻逼DPfij表示前i个人,最后一个正向上菜的人为j

转移考虑当前人是正向上菜还是反向

code
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = (x << 3) + (x << 1) + (c ^ 48);c = getchar();}while(c >= '0' && c <= '9');
	return x;
}
const int maxn = 2505;
int n, h[maxn], ans, f[maxn][maxn];
int main(){
	n = read();
	for(int i = 1; i <= n; ++i)h[i] = read();
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < i; ++j){
			f[i + 1][j] = max(f[i][j] + h[i + 1] * h[i], f[i + 1][j]);
			f[i + 1][i] = max(f[i][j] + h[i + 1] * h[j], f[i + 1][i]);
		}
	}
	for(int i = 0; i < n; ++i)ans = max(ans, f[n][i] + h[n] * h[i]);
	printf("%d\n",ans);
	return 0;
}

B. 渔船

费用流裸题,就我一个学过费用流还爆掉的

因为反向边边权和费用搞挂了

我要是再打挂网络流的板子我就*****!!!

code
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;
const int maxn = 5005;
const int inf = 0x3f3f3f;
inline int read() {
    int x = 0;
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    do {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    } while (c >= '0' && c <= '9');
    return x;
}
int c[maxn];
struct MCMF {
    int head[maxn], tot = 1;
    struct edge {
        int net, to, val, cost;
    } e[maxn << 2 | 1];
    void add(int u, int v, int w, int cost) {
        e[++tot].net = head[u];
        head[u] = tot;
        e[tot].to = v;
        e[tot].val = w;
        e[tot].cost = cost;
    }
    void link(int u, int v, int w, int cost) {
        add(u, v, w, cost);
        add(v, u, 0, -cost);
    }
    int s, t, dis[maxn];
    bool vis[maxn];
    bool spfa() {
        memset(vis, 0, sizeof(vis));
        memset(dis, 0x3f, sizeof(dis));
        dis[s] = 0;
        queue<int> q;
        q.push(s);
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            vis[x] = 0;
            for (int i = head[x]; i; i = e[i].net) {
                int v = e[i].to;
                if (e[i].val > 0 && dis[v] > dis[x] + e[i].cost) {
                    dis[v] = dis[x] + e[i].cost;
                    if (!vis[v]) {
                        q.push(v);
                        vis[v] = 1;
                    }
                }
            }
        }
        return dis[t] != dis[maxn - 1];
    }
    int dfs(int x, int from) {
        if (from <= 0 || x == t) return from;
        int res = from;
        vis[x] = 1;
        for (int i = head[x]; i; i = e[i].net) {
            int v = e[i].to;
            if (!vis[v] && e[i].val > 0 && dis[v] == dis[x] + e[i].cost) {
                int k = dfs(v, min(res, e[i].val));
                res -= k;
                e[i].val -= k;
                e[i ^ 1].val += k;
                if (res <= 0) break;
            }
        }
        return from - res;
    }
    int mcmf() {
        int ans = 0;
        while (spfa()) ans += dis[t] * dfs(s, inf);
        return ans;
    }
    
    void init() {
        int n = read(), a = read(), b = read(), cost = read(), fa = read(), fb = read();
        for (int i = 1; i <= n; ++i) c[i] = read();
        s = maxn - 5;
        t = s + 1;
        for (int i = 1; i <= n; ++i) link(s, i, inf, cost);
        for (int i = 1; i <= n; ++i) link(s, i + n, c[i], 0);
        for (int i = 1; i <= n; ++i) link(i, t, c[i], 0);
        for (int i = 1; i <= n - a - 1; ++i) link(i + n, i + a + 1, c[i], fa);
        for (int i = 1; i <= n - b - 1; ++i) link(i + n, i + b + 1, c[i], fb);
		for (int i = 1; i < n; ++i) link(i, i + 1, inf, 0);
        printf("%d\n", mcmf());
    }
} w;
int main() {
    w.init();
    return 0;
}
posted @   Chen_jr  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示