UVA 10189- Minesweeper

Minesweeper UVA Problem

I am having trouble understanding or solving the matrices/2D Array questions. I cam across this question on Competetive Programming book.

LINK- Online Judge

I would be really grateful if someone can help me through this. A tutorial for this in PYTHON would be really appreciated.

Thank you!

I think you should use dynamic programming to solve it.

Hi Aryan, I am new to competetive programming, .I found a pdf of the same book you got this ques from, Can you please tell me whether that book is a good place to start?
anyways,I was able to solve that problem in c++(the problem is kinda fussy about the output presentation):

#include<bits/stdc++.h>
using namespace std;
int fno=0;

void output(char arr[][102],int n,int m){
cout<<“Field #”<<fno<<’:’<<’\n’;
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++)
cout<<arr[i][j];
cout<<’\n’;
}
}

void CalcMine(char arr[][102],int n,int m){
arr[n][m]=’’;
if(arr[n-1][m-1]!=’
’)arr[n-1][m-1]++;
if(arr[n-1][m]!=’’)arr[n-1][m]++;
if(arr[n-1][m+1]!=’
’)arr[n-1][m+1]++;
if(arr[n][m-1]!=’’)arr[n][m-1]++;
if(arr[n][m+1]!=’
’)arr[n][m+1]++;
if(arr[n+1][m-1]!=’’)arr[n+1][m-1]++;
if(arr[n+1][m]!=’
’)arr[n+1][m]++;
if(arr[n+1][m+1]!=’*’)arr[n+1][m+1]++;
}

int main(){
char arr[102][102];
int n,m;
cin>>n>>m ;
while(true){
fno++;
memset(arr, ‘0’, sizeof(char)102102);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char temp;
cin>>temp;
if(temp==’*’){
CalcMine(arr,i+1,j+1);
}
}
}
int kn=n,km=m;
cin>>n>>m;
output(arr,kn,km);
if(n==0){
break;
}
cout<<’\n’;
}

return 0;

}