airplane game



2
7
1 2 0 0 1
2 0 0 1 0
0 1 2 0 1
1 0 0 2 1
0 2 1 0 1
0 1 2 2 2
1 0 1 1 0
7
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2


************************************

#include <iostream>
using namespace std;

#define SIZE 12

int data[SIZE][5];//

int N;//case的行数
int count;//最终钱币数
int tmp_count;
int mid;//飞机启示位置



void DFS(int step,int st){
	
	if(step == N){
		if(tmp_count>=count){
			count = tmp_count;

		}
		if(tmp_count<0){
			count = -1;
		}
		
		return;
	}

	int left = 0;//左右位置
	int right = 0;
	if(st == 0){
		left = 0;
		right = 1;
	}
	else if(st == 4){
		left = 3;
		right = 4;
	}
	else{
		left = st-1;
		right = st+1;
	}

	for(int k=left;k<=right;k++){//从左到右遍历三种情况
		if(data[step][k] == 1){//碰到 1
			tmp_count++;//钱币加 1
			DFS(step+1,k);//叠代加 1
			tmp_count--;//回朔
		}
		if(data[step][k] == 2){
			tmp_count--;
			DFS(step+1,k);
			tmp_count++;
		}
		if(data[step][k] == 0){
			DFS(step+1,k);
		}
	}

}

int main(int argc, char *argv[]){
	freopen("input.txt","r",stdin);
	int Case;
	scanf("%d",&Case);

	for(int i=0;i<Case;i++){
		scanf("%d",&N);
		count = 0;
		for(int m=N-1;m>=0;m--){
			for(int n=0;n<5;n++){
				scanf("%d ",&data[m][n]);
			}
		}

		count = 0;//初始化
		tmp_count = 0;
		mid = 2;

		int tmp_data[12][5];//存储原始数据到中间数组
		for(int i=0;i<N;i++){
			for(int j=0;j<5;j++){
				tmp_data[i][j] = data[i][j];
			}
		}

		for(int q=0;q<N-5;q++){//遍历所有炸弹情况

			for(int i=0;i<N;i++){//恢复原始数组 
				for(int j=0;j<5;j++){
					data[i][j] = tmp_data[i][j];
				}
			}

			for(int i=q;i<q+5;i++){//将5*5 区域中所有敌机消灭
				for(int j=0;j<5;j++){
					if(data[i][j] == 2){
						data[i][j] =0;
					}
				}
			}
			DFS(0,mid);//叠代
		}

		//DFS(0,mid);

		printf("%d\n",count);
	}
	return 1;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值