#include <iostream>
#include <fstream>
using namespace std;
int main(){
//数据读取
ifstream in("input.txt", ios::in);
if (!in.is_open()){
cout << "Error opening file";
exit(1);
}
char ch;
int n = in.get() - '0';//读取n
//cout << n << endl;
in.get();
int** m = new int*[n];//生产n*n阶的矩阵存放数据
for (int i = 0; i < n; i++){
m[i] = new int[n]();
}
int k = 0;
int j = 0;
int num = 0;
while (!in.eof())
{
j = k;
while ((ch = in.get()) != '\n'){
num = ch - '0';
//cout << m[k][j] << endl;
j++;
if ((ch = in.get()) != ' '){
while (ch != ' ' && ch != '\n')
{
if (in.eof())break;
num *= 10;
num += ch - '0';
ch = in.get();
}
}
m[k][j] = num;
if (ch == '\n')break;
if (in.eof())break;
}
k++;
}
in.close();
//数据处理
for (int r = 0; r < n-2; r++){
for (int i = 0; i < n-r-2; i++){
int j = r - i+2;
for (int k = i + 1; k < j; k++){
m[i][j] = m[i][j]<(m[i][k] + m[k + 1][j]) ? m[i][j]:(m[i][k] + m[k][j]);
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout << m[i][j] << " ";
}
cout << endl;
}
cout << endl;
cout << "最小租金为:" << m[0][n - 1] << endl;
return 0;
}
租用游艇问题
最新推荐文章于 2021-12-04 19:39:20 发布