• 【luogu P1850 换教室】 题解


    题目链接:https://www.luogu.org/problemnew/show/P1850

    难的不在状态上,难在转移方程。

    (话说方程写错居然还有84分= =)

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define ll long long
    using namespace std;
    const ll maxn = 2010;
    ll n, m, v, e, c[maxn], d[maxn], u[maxn][maxn], a, b, w;
    double k[maxn], l[maxn], dp[maxn][maxn][2], ans = 1e9;
    int main()
    {
        //freopen("change.in","r",stdin);
        ios::sync_with_stdio(false);
        memset(u, 63, sizeof(u));
        memset(dp, 127, sizeof(dp));
        cin>>n>>m>>v>>e;
        for(ll i = 1; i <= n; i++)
        cin>>c[i];
        for(ll i = 1; i <= n; i++)
        cin>>d[i];
        for(ll i = 1; i <= n; i++)
        {cin>>k[i]; l[i] = 1-k[i];}
        for(ll i = 1; i <= e; i++)
        {
            cin>>a>>b>>w;
            u[a][b] = min(w, u[a][b]);
            u[b][a] = min(w, u[b][a]);
        }
        for(ll q = 1; q <= v; q++)
            for(ll i = 1; i <= v; i++)
                for(ll j = 1; j <= v; j++)
                if(i != q && j != q && i != j) u[i][j] = min(u[i][j], u[i][q] + u[q][j]);
        for(ll i = 1; i <= v; i++) u[i][i] = u[i][0] = u[0][i] = 0;
        dp[1][0][0] = dp[1][1][1] = 0;
        for(ll i = 2; i <= n; i++)
        {
            ll x1 = c[i], x2 = c[i-1], y1 = d[i], y2 = d[i-1];
            dp[i][0][0] = dp[i-1][0][0] + u[x2][x1];
            for(ll j = 0; j <= min(i, m); j++)
            {
                dp[i][j][0] = min(dp[i][j][0], min(dp[i-1][j][0] + u[x2][x1], dp[i-1][j][1] + l[i-1] * u[x2][x1] + k[i-1] * u[y2][x1]));
                dp[i][j][1] = min(dp[i][j][1], min(dp[i-1][j-1][0] + u[x2][x1] * l[i] + u[x2][y1] * k[i], dp[i-1][j-1][1] + k[i-1] * l[i] * u[y2][x1] + l[i] * l[i-1] * u[x2][x1] + k[i] * k[i-1] * u[y2][y1] + l[i-1] * k[i] * u[x2][y1]));	
            }
        }	
        for(ll i = 0; i <= m; i++)
        ans = min(ans, min(dp[n][i][0], dp[n][i][1]));
        printf("%0.2lf",ans);
        return 0;
    }
    
    
    
  • 相关阅读:
    comm---两个文件之间的比较
    fgrep---指定的输入文件中的匹配模式的行
    zip---解压缩文件
    unzip---解压缩“.zip”压缩包。
    tar---打包,解压缩linux的文件和目录
    scp---远程拷贝文件
    make---GNU编译工具
    gcc---C/C++ 编译器
    expr---计算工具
    curl -w 支持的参数
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9908956.html
Copyright © 2020-2023  润新知