-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmagicGrid.cpp
More file actions
50 lines (39 loc) · 853 Bytes
/
magicGrid.cpp
File metadata and controls
50 lines (39 loc) · 853 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int getMinLife(int **mg, int si, int sj, int r, int c)
{
if( (si == r-1 && sj == c-2) || (si == r-2 && sj == c-1) )
{
return 1;
}
int option1 = getMinLife(mg, si+1, sj, r, c);
int option2 = getMinLife(mg, si, sj+1, r, c);
int ans = min(option1, option2);
return ans;
}
int main()
{
int t;
cin >> t;
while(t--)
{
int r, c;
cin >> r >> c;
int **mg = new int*[r];
for(int i = 0; i < r; i++)
{
mg[i] = new int[c];
for(int j = 0 ; j < c; j++)
{
cin >> mg[i][j];
}
}
int minLife = getMinLife(mg, 0, 0, r, c);
for(int i = 0; i < r; i++)
{
delete [] mg[i];
}
delete [] mg;
}
return 0;
}