Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // Input:
- // 6 5
- // 0 1 0 2 0
- // 0 0 0 0 1
- // 0 0 1 1 1
- // 1 0 1 0 0
- // 0 0 1 0 0
- // 1 1 0 0 1
- // Output:
- // 5
- int A[6][5];
- int n, m, ans;
- void solve(int row, int col, int temp, int bomb, int effect){
- if(row == -1){
- ans = max(ans, temp);
- return;
- }
- for(int i=-1; i<=1; ++i){
- if(col+i < 0 || col+i >= m)
- continue;
- if(A[row][col+i] == 1 || A[row][col+i] == 0){
- if(bomb == 0){
- solve(row-1, col+i, temp+A[row][col+i], bomb, effect-1);
- }
- else{
- solve(row-1, col+i, temp+A[row][col+i], bomb, effect);
- }
- }
- else{
- if(bomb == 0){
- if(effect > 0)
- solve(row-1, col+i, temp, bomb, effect-1);
- }
- else{
- solve(row-1, col+i, temp, 0, 5);
- }
- }
- }
- }
- int main() {
- cin>>n>>m;
- for(int i=0; i<n; ++i)
- for(int j=0; j<m; ++j)
- cin>>A[i][j];
- solve(5, 2, 0, 1, 0);
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement