Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void updateMatrix(int r,int c,int mat[][10]){
- if(r<0){
- return;
- }
- int upLimit=max(0,r-4);
- for(int i=r;i>=upLimit;i--){
- for(int j=0;j<=4;j++){
- if(mat[i][j]=='2'){
- mat[i][j]='0';
- }
- }
- }
- }
- int cal(int r, int c,int bomb, int mat[][10]){
- if(r<=0 || c>=5 || c<0) return 0;
- int answer=0;
- if(r>0 && mat[r-1][c]!=2)
- answer=max(answer, (mat[r-1][c]==1?1:0) + cal(r-1,c,bomb,mat));
- if(r>0 && c>0 && mat[r-1][c-1]!=2)
- answer=max(answer, (mat[r-1][c-1]==1?1:0) + cal(r-1,c-1,bomb,mat));
- if(r>0 && c>0 && c<4 && mat[r-1][c+1]!=2)
- answer=max(answer, (mat[r-1][c+1]==1?1:0) + cal(r-1,c+1,bomb,mat));
- if(answer==0 && bomb>0){
- updateMatrix(r-1,c,mat);
- answer=cal(r,c,bomb-1,mat);
- }
- return answer;
- }
- int main() {
- int t;
- cin>>t;
- while(t--){
- int r,c;
- cin>>r>>c;
- int mat[10][10];
- for(int i=0; i<r; i++)
- for(int j=0; j<c; j++)
- cin>>mat[i][j];
- cout<<cal(r+1,c/2,1,mat)<<endl;
- }
- }
Add Comment
Please, Sign In to add comment