Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int a[15][5], col = 5, row;
- int solve(int x, int y, int bomb, int effect, int coin){
- if(x < 0 or y < 0 or y >= col){
- return coin;
- }
- if(a[x][y] == 2 and bomb == 0 and effect < 0){
- return coin;
- }
- if(a[x][y] == 2 and bomb == 1){
- bomb = 0;
- effect = 5;
- }
- if(bomb == 0){
- effect--;
- }
- if(a[x][y] == 1){
- coin++;
- }
- 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)));
- }
- int main(){
- int t, cases=1;
- cin >> t;
- while(t--){
- cin >> row;
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++){
- cin >> a[i][j];
- }
- }
- 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)));
- cout << "#" << cases++ << " " << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement