HDU 4536 XCOM Enemy Unknown

题目连接:XCOM Enemy Unknown

解题思路:腾讯马拉松复赛第二场,数据量不是很大,可以直接搜索,注意回溯的时候要把所有的值恢复到搜索前的值。

 #include<stdio.h>
#include<string.h>

struct A{
	int fair, comp;
};

typedef struct A node; 
int at[110][3], max, n, m, k;
node map[20];

int judge(){
	int i;
	for(i = 0; i < n; i++){
		if(map[i].fair > 5){
			return 0;
		}
	}
	return 1;
}

void DFS(int depth){
	int i, j, tem;
	if(depth > max){
		max = depth;
	}
	if(depth >= k){
		return;
	}
	for(i = 0; i < 3; i++){
		tem = map[at[depth][i]].fair;
		map[at[depth][i]].fair -= 2;
		map[at[depth][(i + 1) % 3]].fair += 2;
		map[at[depth][(i + 2) % 3]].fair += 2;
		for(j = 0; j < n; j++){
			if(map[j].comp == map[at[depth][(i + 1) % 3]].comp && j != at[depth][(i + 1) % 3]){
				map[j].fair++;
			}
			if(map[j].comp == map[at[depth][(i + 2) % 3]].comp && j != at[depth][(i + 2) % 3]){
				map[j].fair++;
			}
		}		
		if(judge()){
			DFS(depth + 1);
		}
		map[at[depth][i]].fair = tem;
		map[at[depth][(i + 1) % 3]].fair -= 2;
		map[at[depth][(i + 2) % 3]].fair -= 2;
		for(j = 0; j < n; j++){
			if(map[j].comp == map[at[depth][(i + 1) % 3]].comp && j != at[depth][(i + 1) % 3]){
				map[j].fair--;
			}
			if(map[j].comp == map[at[depth][(i + 2) % 3]].comp && j != at[depth][(i + 2) % 3]){
				map[j].fair--;
			}
		}
	}
}

int main(){
	int i, j, t, tot = 1;
	scanf("%d", &t);
	while(t--){
		max = 0;
		scanf("%d%d%d", &n, &m, &k);
		for(i = 0; i < n; i++){
			scanf("%d", &map[i].comp);
		}
		for(i = 0; i < n; i++){
			scanf("%d", &map[i].fair);
		}
		for(i = 0; i < k; i++){
			scanf("%d%d%d", &at[i][0], &at[i][1], &at[i][2]);
		}
		DFS(0);
		printf("Case #%d: %d\n", tot++, max);
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值