1 条题解

  • 1
    @ 2024-9-13 13:49:54

    参考答案:

    #include<iostream>
    #include<queue>
    #include<cstring>
    
    using namespace std;
    typedef pair<int, int> PII;
    
    const int N = 110;
    int w[N][N];
    int price[N];
    int st[N], dis[N], level[N];
    int m, n;
    int res = 1e9;
    int dijkstra(int l, int r)
    {
        memset(dis, 0x3f, sizeof(dis));
        memset(st, 0, sizeof(st));
        dis[0] = 0;
        for (int i = 1; i <= n + 1; ++i)
        {
            int t = -1;
            for (int j = 0; j <= n; ++j)
            {
                if (!st[j] && (t == -1 || dis[t] > dis[j])) t = j;
            }
            st[t] = 1;
            for (int j = 1; j <= n; ++j)
            {
                if (level[j] >= l && level[j] <= r) dis[j] = min(dis[j], dis[t] + w[t][j]);
            }
        }
    
        return dis[1];
    }
    int main()
    {
        cin >> m >> n;
        memset(w, 0x3f, sizeof(w));
        for (int i = 1; i <= n; ++i) w[i][i] = 0;
    
        for (int i = 1; i <= n; ++i)
        {
            int p, l, x;
            cin >> p >> level[i] >> x;
            w[0][i] = min(w[0][i], p);
            while (x--)
            {
                int t, v;
                cin >> t >> v;
                w[t][i] = min(w[t][i], v);
            }
        }
        for (int i = level[1] - m; i <= level[1]; ++i)
        {
            res = min(res, dijkstra(i, i + m));
        }
        cout << res << endl;
        return 0;
    }
    
    • 1

    信息

    ID
    5360
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    3
    已通过
    1
    上传者