深搜,遍历每个方块,去找周围温度更高的房子,重复这个过程,然后走无可走之后,将最高的温度,传导到每一个路径上
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
// #include <cmath>
using namespace std;
int step = 0;
int max_class = 0;
int max_num = 0;
int idex[5] = {1,1,-1,-1,1};
int dfs(int x,int y, vector<vector<int>>& map, vector<vector<int>>& re,int last_temp){
if(x < 0 || y < 0 || x >= map.size() || y >= map.size()){
return -1;
}
if(map[x][y] < last_temp){
return -1;
}
if(re[x][y] != 0)
return max(map[x][y],re[x][y]);
re[x][y] = -1;
int x_bias = 0, y_bias = 0;
int new_temp = 0;
int temp_max_temp = map[x][y];
int re_x = -1,re_y = -1;
for(int x_bias = 0; x_bias <= step; x_bias++){
for(int y_bias = 0; y_bias <= step - x_bias; y_bias++){
for(int i = 0; i < 4; i++){
auto temp_x = x + idex[i] * x_bias, temp_y = y + idex[i+1] * y_bias;
if(temp_x < 0 || temp_y < 0 || temp_x >= map.size() || temp_y >= map.size())
continue;
if(map[temp_x][temp_y] > temp_max_temp){
temp_max_temp = map[temp_x][temp_y];
re_x= temp_x;
re_y = temp_y;
}
}
// new_temp = std::max(new_temp,dfs(x+x_bias,y+y_bias,map,re,map[x][y]));
// new_temp = std::max(new_temp,dfs(x+x_bias,y-y_bias,map,re,map[x][y]));
// new_temp = std::max(new_temp,dfs(x-x_bias,y+y_bias,map,re,map[x][y]));
}
}
if(re_x != -1)
new_temp = std::max(new_temp,dfs(re_x,re_y,map,re,map[x][y]));
// if(x == 1 && y == 1){
// std::cout << "---" << new_temp <<std::endl;
// }
re[x][y] = max(max(new_temp,map[x][y]),re[x][y]);
// cout << re[x][y] <<" " << x << " " << y <<"\n";
return re[x][y];
}
int main(){
int m = 0, n = 0;
cin >> m >> n ;
step = n;
vector<vector<int>> map(m,vector<int>(m,0));
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
cin >> map[i][j];
}
}
vector<vector<int>> re(m,vector<int>(m,0));
unordered_map<int,int> ans;
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
if(re[i][j] == 0){
auto temp = dfs(i,j,map,re,0);
ans[temp] = 0;
}
}
}
// for(int i = 0; i < m; i++){
// for(int j = 0; j < m; j++){
// cout << re[i][j] << " ";
// }
// cout << std::endl;
// }
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
ans[re[i][j]]++;
}
}
int max_ans = 0;
int max_id = 0;
for(auto au : ans){
if(au.second > max_ans){
max_id = au.first;
max_ans = au.second;
}
}
std::cout << ans.size() << " " << max_ans;
return 0;
}