[] NOI2019 route home

Face questions

answer

See synchronization race \ (m \ leq 2 \ times 10 ^ 5, q_i \ leq 1000 \) I flashes, paid a \ (\ mathrm {O} ( mt) \) a large force is then \ ( \ mathrm {AC} \) of this title

Set \ (f [i] [j ] \) represents the current at the \ (I \) sites, time for \ (J \) minimum annoyance, \ (F. (X) = Ax of ^ 2 + Bx + C \) .

Each edge is then enumeration \ (I \) , can be obtained: \ (F [y_i] [J] = \ min \ F {[x_i] [P_i] F. + (J - Q_I) \} \) .

Direct \ (\ mathrm {DP} \ ) can.

Code

#include <cstdio>
#include <algorithm>

inline int read()
{
    int data = 0, w = 1; char ch = getchar();
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
    return data * w;
}

const int maxn(1e5 + 10), maxm(2e5 + 10), T(1010), INF(0x3f3f3f3f);
int n, m, A, B, C, maxQ, f[maxn][T];
struct node { int x, y, p, q; } L[maxm];
inline int operator < (const node &lhs, const node &rhs) { return lhs.q < rhs.q; }
inline int F(int x) { return x * x * A + x * B + C; }

void solve()
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= maxQ; j++) f[i][j] = INF;
    for (int j = 0; j <= maxQ; j++) f[1][j] = F(j);
    for (int i = 1; i <= m; i++)
    {
        int x = L[i].y;
        for (int j = L[i].q; j <= maxQ; j++)
            f[x][j] = std::min(f[x][j], f[L[i].x][L[i].p] + F(j - L[i].q));
    }
    int ans = INF;
    for (int j = 1; j <= maxQ; j++)
        ans = std::min(ans, f[n][j] + j - C);
    printf("%d\n", ans);
}

int main()
{
    n = read(), m = read(), A = read(), B = read(), C = read();
    for (int i = 1; i <= m; i++) L[i] = (node) {read(), read(), read(), read()};
    for (int i = 1; i <= m; i++) maxQ = std::max(maxQ, L[i].q);
    std::sort(L + 1, L + m + 1), solve();
    return 0;
}

Guess you like

Origin www.cnblogs.com/cj-xxz/p/11203703.html