lelouche29

spaceship game Samsung

Aug 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void updateMatrix(int r,int c,int mat[][10]){
  5.     if(r<0){
  6.         return;
  7.     }
  8.     int upLimit=max(0,r-4);
  9.     for(int i=r;i>=upLimit;i--){
  10.         for(int j=0;j<=4;j++){
  11.             if(mat[i][j]=='2'){
  12.                 mat[i][j]='0';
  13.             }
  14.         }
  15.     }
  16. }
  17.  
  18. int cal(int r, int c,int bomb, int mat[][10]){
  19.     if(r<=0 || c>=5 || c<0) return 0;
  20.  
  21.     int answer=0;
  22.     if(r>0 && mat[r-1][c]!=2)
  23.         answer=max(answer, (mat[r-1][c]==1?1:0) + cal(r-1,c,bomb,mat));
  24.     if(r>0 && c>0 && mat[r-1][c-1]!=2)
  25.         answer=max(answer, (mat[r-1][c-1]==1?1:0) + cal(r-1,c-1,bomb,mat));
  26.     if(r>0 && c>0 && c<4 && mat[r-1][c+1]!=2)
  27.         answer=max(answer, (mat[r-1][c+1]==1?1:0) + cal(r-1,c+1,bomb,mat));
  28.    
  29.     if(answer==0 && bomb>0){
  30.         updateMatrix(r-1,c,mat);
  31.         answer=cal(r,c,bomb-1,mat);
  32.     }
  33.  
  34.     return answer;
  35.    
  36. }
  37.  
  38. int main() {
  39.     int t;
  40.     cin>>t;
  41.     while(t--){
  42.         int r,c;
  43.         cin>>r>>c;
  44.         int mat[10][10];
  45.         for(int i=0; i<r; i++)
  46.             for(int j=0; j<c; j++)
  47.                 cin>>mat[i][j];
  48.  
  49.         cout<<cal(r+1,c/2,1,mat)<<endl;
  50.     }
  51. }
Add Comment
Please, Sign In to add comment