BZOJ 1003. [ZJOI2006] logistics and transport

 

$ cost [i] [j] $ denotes $ $ I $ J $ to day days a daily minimum cost down when the same route, i.e. $ 1 to $ $ m $ is the shortest. dijkstra can be.
Then $ dp [i] $ $ I $ represents the first day of the minimum cost
$ dp [i] = min ( dp [j] + cost [j + 1] [i] * (i - j) + k) $

#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;

const int INF = 10000000;
const int N = 110;
int cost[N][N], dp[N], n, m, k, e;
vector<pii> G[N];
bool ban[N][N], unable[N], done[N];
int dis[N];

inline void checkmin(int &a, int b) {
    if (a > b) a = b;
}

int dijkstra(int l, int r) {
    for (int i = 1; i <= m; i++) {
        unable[i] = 0;
        done[i] = 0;
        dis[i] = INF;
        for (int j = l; j <= r; j++)
            unable[i] |= ban[j][i];
    }
    if (unable[1] || unable[m]) return INF;
    priority_queue<pii, vector<pii>, greater<pii> > que;
    dis[1] = 0;
    que.push(pii(0, 1));
    while (!que.empty()) {
        auto pp = que.top(); que.pop();
        int u = pp.se;
        if (done[u]) continue;
        done[u] = 1;
        for (auto p: G[u]) {
            int v = p.se, c = p.fi;
            if (!unable[v] && dis[v] > dis[u] + c) {
                December [v] = December [u] + c;
                que.push (PII (dis [v], v));
            }
        }
    }
    return dis[m];
}

int main() {
    //freopen("in.txt", "r", stdin);
    scanf("%d%d%d%d", &n, &m, &k, &e);
    for (int u, v, c; e--; ) {
        scanf("%d%d%d", &u, &v, &c);
        G[u].push_back(pii(c, v));
        G[v].push_back(pii(c, u));
    }
    int q;
    scanf("%d", &q);
    for (int u, a, b; q--; ) {
        scanf("%d%d%d", &u, &a, &b);
        for (int i = a; i <= b; i++)
            board [i] [u] = 1 ;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cost[i][j] = dijkstra(i, j);
    for (int i = 1; i <= n; i++) {
        dp[i] = cost[1][i] * i;
        for (int j = 1; j < i; j++)
            checkmin(dp[i], dp[j] + cost[j + 1][i] * (i - j) + k);
    }
    printf("%d\n", dp[n]);
    return 0;
}
View Code

Guess you like

Origin www.cnblogs.com/Mrzdtz220/p/12230539.html