• HDU 1045


    http://acm.hdu.edu.cn/showproblem.php?pid=1045

    #include <bits/stdc++.h>
    using namespace std;
    int n;
    char ch[10][10];
    int dp[4][2] = {-1,0,1,0,0,-1,0,1};
    int ans;
    int check(int x,int y){
        if(ch[x][y] != '.') return 0;
        for(int i = 0; i < 4; i++){
            int dx = x + dp[i][0];
            int dy = y + dp[i][1];
            while(true){
                if(dx < 0 || dx >= n || dy < 0 || dy >= n || ch[dx][dy] == 'X' )
                    break;//这里不是return 0
                else if(ch[dx][dy] == '1')
                    return 0;
                dx += dp[i][0];
                dy += dp[i][1];
            }
        }
        return 1;
    }
    void dfs(int x){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(check(i,j)){
                    ch[i][j] = '1';
                    dfs(x + 1);
                    ch[i][j] = '.';
                }
            }
        }
        if(ans < x)
            ans = x;
    }
    int main(){
        //freopen("in","r",stdin);
        ios::sync_with_stdio(0);
        while(cin >> n){
            if(!n) break;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++)
                    cin >> ch[i][j];
            }
            ans = 0;
            dfs(0);
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    货币
    沙漏
    秋季学习总结
    三个老师
    介绍自己
    redis 的部分配置
    第二次博客作业
    第一次阅读作业
    shell_通配符
    shell_/dev/null,>和&
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12681408.html
Copyright © 2020-2023  润新知