#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1000;
int r[maxn][maxn];
int m[maxn];
int n;
//m[i]表示起点到第i站的最少租金费用。
// m[i] = min{m[k] + m[k][i], m[i]}
int money_dp(){
for(int i = 1; i <= n; i++){
m[i] = r[0][i];
for(int j = i-1; j > 0; j--){
if(m[i] > m[j] + r[j][i]){
m[i] = m[j] + r[j][i];
}
}
}
return m[n];
}
int main()
{
int num = 0, a;
while(scanf("%d", &n) == 1){
if(n == 0) { break; }
else{
printf("case %d:\n", ++num);
for(int i = 0; i < n; i++){
for(int j = i+1; j <= n; j++){
scanf("%d", &a);
r[i][j] = a;
}
}
printf("%d\n", money_dp());
}
}
return 0;
}
/**********************
3
2 3 6
1 3
2
3
4 7 9
4 5
6
*********************/
游船问题II(DP)
最新推荐文章于 2023-09-26 17:21:26 发布