最低通行费 AcWing 1018 题解

题目来自www.acwing.com
题目
在这里插入图片描述
分析过程
在这里插入图片描述
代码实现

#include<iostream>
#include<cstring>

using namespace std;

const int N = 110;
int f[N][N], w[N][N];
int n;

int main(){
    
    
    cin >> n;
    
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> w[i][j];
            
    memset(f, 0x3f, sizeof f);
    //f[1][1] = w[1][1];
    f[0][1] = f[1][0] = 0;
    for(int i = 1;i <= n; i++){
    
    
        for(int j = 1; j <= n; j++)
            f[i][j] = min(f[i - 1][j], f[i][j - 1]) + w[i][j];
    }
    
    cout << f[n][n] << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44879626/article/details/108606948