zoukankan      html  css  js  c++  java
  • [POJ1321]棋盘问题

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 using namespace std;
     5 int n,m,cnt;
     6 bool column[10];
     7 char f[10][10];
     8 void dfs(int step,int t)
     9 {
    10     if(t>m)
    11     {
    12         ++cnt;
    13         return;
    14     }
    15     if(step>n)return;
    16     for(int i=1;i<=n;++i)
    17         if(!column[i] && f[step][i]=='#')
    18         {
    19             column[i]=1;
    20             dfs(step+1,t+1);
    21             column[i]=0;
    22         }
    23     dfs(step+1,t);
    24 }
    25 int main()
    26 {
    27 //    freopen("board.in","r",stdin);
    28 //    freopen("board.out","w",stdout);
    29     while(~scanf("%d%d",&n,&m))
    30     {
    31         if(n==-1 && m==-1) break;
    32         if(m>n)
    33         {
    34             printf("0");
    35             continue;
    36         }
    37         for(int i=1;i<=n;++i)
    38             for(int j=1;j<=n;++j)
    39                 cin>>f[i][j];
    40         cnt=0;
    41         memset(column,0,sizeof(column));
    42         dfs(1,1);
    43         printf("%d
    ",cnt);
    44     }
    45 }
    46 /*
    47 2 1
    48 #.
    49 .#
    50 4 4
    51 ...#
    52 ..#.
    53 .#..
    54 #...
    55 -1 -1
    56 */
     
  • 相关阅读:
    一个Fragment的实例
    使用LayoutInflater添加一个布局引用
    11F:42点
    11E:分形盒
    11D:猴子摘桃
    11C:寻找边缘
    11B:夺宝探险
    10J:判断整除
    11A:篮球联赛
    10I:核电站
  • 原文地址:https://www.cnblogs.com/__Kgds/p/9454383.html
Copyright © 2011-2022 走看看