#include
using namespace std;
int escapePark(char** park,int n,int m,int k,int s,int i,int j)
{
if(s<k)
return -1;
if(i==n)
return s;
if(j==m)
{
s++;//because going to next row is lossless.
return escapePark(park,n,m,k,s,i+1,j=0);
}
if(park[i][j]==β.β)
{
s=s-3;//2 due to β.β and 1 to take next step
return escapePark(park,n,m,k,s,i,j+1);
}
if(park[i][j]==ββ)
{
s=s+4;//+5 due to 'β and -1 to take next step
return escapePark(park,n,m,k,s,i,j+1);
}
if(park[i][j]==β#β)
{
return escapePark(park,n,m,k,s,i+1,0);
}
}
int main() {
int n,m,k,s;
cin>>n>>m>>k>>s;
char park[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>park[i][j];
int remain=escapePark(park,n,m,k,s,0,0);
if(remain==-1)
cout<<"No";
else
cout<<"Yes"<<remain;
return 0;
}
this is my code for magic park problem, I am getting a type casting error but not understand how to solve it.
Also, every time I send such 2D arrays of undefine dimension as parameter I always got the same type of error. So, besides declaring array globally or taking a fixed-size array, please solve it by passing parameters it will help in other 2D array passing problems.