Advertisement
Mohammad_Dipu_Sultan

Aeroplane Bombing

Oct 13th, 2023
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[15][5], col = 5, row;
  5.  
  6. int solve(int x, int y, int bomb, int effect, int coin){
  7.     if(x < 0 or y < 0 or y >= col){
  8.         return coin;
  9.     }
  10.     if(a[x][y] == 2 and bomb == 0 and effect < 0){
  11.         return coin;
  12.     }
  13.     if(a[x][y] == 2 and bomb == 1){
  14.         bomb = 0;
  15.         effect = 5;
  16.     }
  17.     if(bomb == 0){
  18.         effect--;
  19.     }
  20.     if(a[x][y] == 1){
  21.         coin++;
  22.     }
  23.  
  24.     return max(solve(x-1, y-1, bomb, effect, coin), max(solve(x-1, y, bomb, effect, coin), solve(x-1, y+1, bomb, effect, coin)));
  25. }
  26. int main(){
  27.     int t, cases=1;
  28.     cin >> t;
  29.     while(t--){
  30.         cin >> row;
  31.         for(int i = 0; i < row; i++){
  32.             for(int j = 0; j < col; j++){
  33.                 cin >> a[i][j];
  34.             }
  35.         }
  36.         int ans = max(solve(row-1, 1, 1, 0, 0), max(solve(row-1, 2, 1, 0, 0), solve(row-1, 3, 1, 0, 0)));
  37.         cout << "#" << cases++ << " " << ans << endl;
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement