租用游艇问题

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值