这道题呢,需要用到贪心的性质。因为输出的不仅是是最优的路线,而且还得是升序排列序号。
所以,设立一个结构体,里面存储这条路可以隔开几对,并且他的序号
结构体需要有两个,一个是行,一个是列
之后贪心时,比较函数的重置需要有两个
一个是判断个数,降序排列
之后是判断序号大小,升序排列
话不多说,代码呈上
#include<bits/stdc++.h>
using namespace std;
int m;
int n;
int k;
int l;
int d;
struct node
{
int order;//序号
int cnt;//可以隔开的数目
};
node a[2001];//列
node b[2001];//行
bool cmp_cnt(node x,node y)
{
return x.cnt>y.cnt;
}//个数的重置函数
bool cmp_order(node x,node y)
{
return x.o