hdu 1760 A New Tetris Game

1715 단어 game
http://acm.hdu.edu.cn/showproblem.php?pid=1760
dfs + 바둑 을 두다
코드:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<vector>

#include<queue>

#include<map>

#include<stack>

#include<algorithm>

#include<cmath>



using namespace std;

//#pragma comment(linker,"/STACK:1000000000,1000000000")



#define LL long long



const int N=55;

char a[N][N];

int n,m;

int dfs()

{/*

    for(int i=0;i<n;++i)

    {

        for(int j=0;j<m;++j)

        cout<<a[i][j]<<" ";

        cout<<endl;

    }*/

    int k=0;

    for(int i=1;i<n;++i)

    {

        for(int j=0;j<m-1;++j)

        {

            if(a[i][j]=='1'||a[i-1][j]=='1'||a[i][j+1]=='1'||a[i-1][j+1]=='1')

            continue;

            a[i][j]='1';a[i-1][j]='1';a[i][j+1]='1';a[i-1][j+1]='1';

            if(dfs()==0)

            k=1;

            a[i][j]='0';a[i-1][j]='0';a[i][j+1]='0';a[i-1][j+1]='0';

            if(k)

            break;

        }

        if(k)

        break;

    }

    return k;

}

int main()

{

    //freopen("data.txt","r",stdin);

    while(scanf("%d %d",&n,&m)!=EOF)

    {

        getchar();

        for(int i=0;i<n;++i)

        {

            gets(a[i]);

        }

        if(dfs())

        printf("Yes
"); else printf("No
"); } return 0; }

좋은 웹페이지 즐겨찾기