分析:
注意初始化:
代码
#include<iostream>
#include<cstring>
using namespace std;
const int N = 110;
int f[N][N], w[N][N];
int main()
{
int n; 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[0][1] = 0; 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];
return 0;
}