-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.cpp
More file actions
66 lines (57 loc) · 1.07 KB
/
recursion.cpp
File metadata and controls
66 lines (57 loc) · 1.07 KB
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
#include<iostream>
using namespace std;
#include <bits/stdc++.h>
void traingle(int x) {
if (x <=0){
return;
}
for(int i = 1; i <=x;i++){
cout<<"*";
}
cout<<endl;
traingle(x-1);
}
void printbits(int n){
if(n){
printbits(n/2);
cout<<n%2;
}
}
int gird[100][100];
int maxpathsum(int r, int c){
if(!valid(r,c)){
return 0;
}
if(r == n-1 && c == n-1){
return gird[r][c];
}
int path1 =maxpathsum(r,c+1);
int path2 =maxpathsum(r+1,c);
return gird[r][c] + max(path1,path2);
}
int vis[100][100];
char maze[100][100];
int c=0;
int cntReachableCell(int r,int c){
if(!valid(r,c) || maze[r][c]=='X' || vis[r][c]==1){
return;
}
vis[r][c]=1;
c++;
cntReachableCell(r,c+1);
cntReachableCell(r,c-1);
cntReachableCell(r-1,c);
cntReachableCell(r+1,c);
}
int main()
{
int r,c;
cin>>r>>c;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
cin>>maze[i][j];
}
}
cntReachableCell(r,c);
return 0;
}