Advertisement
urmisaha

Samsung-Maximum Coins Game

Nov 6th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Input:
  5. // 6 5
  6. // 0 1 0 2 0
  7. // 0 0 0 0 1
  8. // 0 0 1 1 1
  9. // 1 0 1 0 0
  10. // 0 0 1 0 0
  11. // 1 1 0 0 1
  12.  
  13. // Output:
  14. // 5
  15.  
  16. int A[6][5];
  17. int n, m, ans;
  18. void solve(int row, int col, int temp, int bomb, int effect){
  19.     if(row == -1){
  20.         ans = max(ans, temp);
  21.         return;
  22.     }
  23.     for(int i=-1; i<=1; ++i){
  24.         if(col+i < 0 || col+i >= m)
  25.             continue;
  26.         if(A[row][col+i] == 1 || A[row][col+i] == 0){
  27.             if(bomb == 0){
  28.                 solve(row-1, col+i, temp+A[row][col+i], bomb, effect-1);
  29.             }
  30.             else{
  31.                 solve(row-1, col+i, temp+A[row][col+i], bomb, effect);
  32.             }
  33.            
  34.         }
  35.         else{
  36.             if(bomb == 0){
  37.                 if(effect > 0)
  38.                     solve(row-1, col+i, temp, bomb, effect-1);
  39.             }
  40.             else{
  41.                 solve(row-1, col+i, temp, 0, 5);
  42.             }
  43.         }
  44.     }
  45. }
  46.  
  47. int main() {
  48.     cin>>n>>m;
  49.     for(int i=0; i<n; ++i)
  50.         for(int j=0; j<m; ++j)
  51.             cin>>A[i][j];
  52.     solve(5, 2, 0, 1, 0);
  53.     cout<<ans<<endl;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement