标签:clu std iss bsp script ane return 技术 NPU
4 4 0000 0000 0000 0000 4 4 0000 0010 0100 0000Sample Output
Yes No
OJ-ID:
HDU-1760
author:
Caution_X
date of submission:
20190929
tags:
DFS+博弈
description modelling:
给定N×M的方格,0为可放方格,1为不可放方格,现在开始轮流放正方形方块,每个方块占4格,由A先开始放,问A能否必胜
major steps to solve it:
博弈中的必胜态:当前所能到达的状态能到达一个必败态,则当前状态为必胜态。
博弈中的必败态:若当前状态到达的所有状态都是必胜态,则当前状态为必败态。
DFS直到不能再放方块,则不能再放方块的那个状态为必败态,然后往前回溯直到最初的状态即可
AC code:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; char Map[55][55]; int DFS(int N,int M) { for(int i = 0; i < N-1; ++i) { for(int j = 0; j < M-1; ++j) { if(Map[i][j]==‘0‘ && Map[i+1][j]==‘0‘ && Map[i][j+1]==‘0‘ && Map[i+1][j+1]==‘0‘) { Map[i][j] = Map[i+1][j] = Map[i][j+1] = Map[i+1][j+1] = ‘1‘; if(!DFS(N,M)) { Map[i][j] = Map[i+1][j] = Map[i][j+1] = Map[i+1][j+1] = ‘0‘; return 1; } Map[i][j] = Map[i+1][j] = Map[i][j+1] = Map[i+1][j+1] = ‘0‘; } } } return 0; //最终没有可放为必败局 } int main() { int N,M; while(cin >> N >> M) { for(int i = 0; i < N; ++i) cin >> Map[i]; if(DFS(N,M)) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
HDU-1760 A New Tetris Game DFS
标签:clu std iss bsp script ane return 技术 NPU
原文地址:https://www.cnblogs.com/cautx/p/11612461.html