zoukankan      html  css  js  c++  java
  • Fire Net HDU 1045

    简单深搜,可以完全暴力,不会超时的。

    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    #define MAX(a,b) (a>b?a:b) 
    char maze[10][10];
    int n, maxn;
    
    void DFS(int step,int count);
    int cheak(int x, int y);
    int main()
    {
        int i;
        while(scanf("%d",&n), n)
        {
            maxn = 0;
            for(i = 0; i < n; i++)
                scanf("%s",maze[i]);
            DFS(0,0);
            printf("%d
    ",maxn);
        }
        return 0;
    }
    
    void DFS(int step,int count)
    {
        int x, y;
        maxn = MAX(maxn,count);
        if(step == n*n)
            return ;
        x = step/n;
        y = step%n;
        if(maze[x][y] == '.' && cheak(x,y))
        {
            maze[x][y] = 'O';
            DFS(step+1,count+1);
            maze[x][y] = '.';
        }
        DFS(step + 1, count);
    }
    
    int cheak(int x, int y)
    {
        int i;
        for(i = x-1; i >= 0; i--)
        {
            if(maze[i][y] == 'O')
                return 0;
            else if(maze[i][y] == 'X')
                break;
        }
        for(i = y-1; i >= 0; i--)
        {
            if(maze[x][i] == 'O')
                return 0;
            else if(maze[x][i] == 'X')
                break;
        }
        return 1;
    }
  • 相关阅读:
    [USACO15FEB][AC自动机][栈] Censoring G
    [USACO06NOV] Round Numbers S
    Emiya家的饭
    dp
    P2498 [SDOI2012]拯救小云公主
    [HEOI2015]小L的白日梦
    SP8064 AMR10J-Mixing Chemicals
    10.24三题
    P4296 [AHOI2007]密码箱
    CF780F
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/3759398.html
Copyright © 2011-2022 走看看