lelouche29

Aeropplane_game_ Samsung

Sep 10th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int mat[15][15];
  5. int b[15][15];
  6.  
  7. void detonate(int row){
  8.     for(int i=row; i >(row-5); i--){
  9.         for(int j=0; j<5; j++){
  10.             b[row-i][j]=0;
  11.             if(i>=0 && mat[i][j]==2){
  12.                 b[row-i][j]=2;
  13.                 mat[i][j]=0;
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. void undetonate(int row){
  20.     for (int i = row; i > row - 5; i--){
  21.         for (int j = 0; j < 5; j++){
  22.             if (i >= 0 && b[row - i][j] == 2)
  23.                 mat[i][j] = 2;
  24.         }
  25.     }
  26. }
  27.  
  28. void solve(int cur_row, int cur_col, int points,int &maxPoints){
  29.     //base condition
  30.     if(cur_col <0 || cur_col>4) return;
  31.  
  32.     if(mat[cur_row-1][cur_col]==1) points+=1;
  33.     else if(mat[cur_row-1][cur_col]==2) points-=1;
  34.  
  35.     if(cur_row==0) {
  36.         maxPoints=max(maxPoints,points);
  37.         return;
  38.     }
  39.     else{
  40.         solve(cur_row -1, cur_col +1, points, maxPoints);
  41.         solve(cur_row -1, cur_col -1, points, maxPoints);
  42.         solve(cur_row -1, cur_col, points, maxPoints);
  43.     }
  44. }
  45.  
  46. int main() {
  47.     int t;
  48.     cin>>t;
  49.     while(t--){
  50.         int n;
  51.         cin>>n;
  52.  
  53.         for(int i=0; i<n; i++)
  54.             for(int j=0; j<5; j++)
  55.                 cin>>mat[i][j];
  56.        
  57.         int maxPoints=-1;
  58.         for(int i=n-1; i>=0; i--){
  59.             int points=-1;
  60.             detonate(i);
  61.             solve(n,2,0,points);
  62.             maxPoints= max(points,maxPoints);
  63.             undetonate(i);
  64.         }
  65.         int ans=maxPoints <0 ? -1 : maxPoints;
  66.         cout<<ans<<endl;      
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment