-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowJunyi.cpp
82 lines (77 loc) · 1.28 KB
/
snowJunyi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
using namespace std;
int r,c;
int xue[100][100];
int deep = 1;
int snow(int n,int ci){
if (deep > 101) {
return 0;
}
deep++;
int a,b,m,q;
a = n/c;
b = n%c-1;
if (b==-1){
b = c-1;
}
if (n%c==0){
a-=1;
}
ci++;
m = 0;
bool yes = false;
if (a-1>=0 && xue[a-1][b]<xue[a][b]){
yes = true;
q = snow(n-r,ci);
if (q>m){
m = q;
}
}
if (a+1<r && xue[a+1][b]<xue[a][b]){
q = snow(n+r,ci);
yes = true;
if (q>m){
m = q;
}
}
if (b-1>=0 && xue[a][b-1]<xue[a][b]){
q = snow(n-1,ci);
yes = true;
if (q>m){
m = q;
}
}
if (b+1<c && xue[a][b+1]<xue[a][b]){
q = snow(n+1,ci);
yes = true;
if (q>m){
m = q;
}
}
if (yes==false){
deep--;
return ci;
}
deep--;
return m;
}
int snowJunyi(){
cin >> r >> c;
for (int i = 0;i<r;i++)
{
for (int j = 0;j<c;j++)
{
scanf("%d",&xue[i][j]);
}
}
int m = 0;
int q;
for (int i = 0;i<r*c;i++){
q = snow(i,0);
if (m<q){
m = q;
}
}
cout << m;
return 0;
}