心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0

以下是我的代码:
/*
 * Author:  lee1r
 * Created Time:  2011/8/6 9:35:45
 * File Name: poj1321.cpp
 
*/
#include
<iostream>
#include
<sstream>
#include
<fstream>
#include
<vector>
#include
<list>
#include
<deque>
#include
<queue>
#include
<stack>
#include
<map>
#include
<set>
#include
<bitset>
#include
<algorithm>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<cctype>
#include
<cmath>
#include
<ctime>
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define Half(x) ((x)>>1)
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int kInf(0x7f7f7f7f);
const double kEps(1e-8);
typedef 
long long int64;
typedef unsigned 
long long uint64;

const int kMaxn(10);

int n,k;
int64 ans;
bool g[kMaxn][kMaxn],row[kMaxn],col[kMaxn];

void dfs(int depth,int now)
{
    
if(now==k)
    {
        ans
++;
        
return;
    }
    
if(depth>n)
        
return;
    dfs(depth
+1,now);
    
for(int i=1;i<=n;i++)
        
if(!row[i] && !col[i] && g[depth][i])
        {
            row[i]
=col[i]=true;
            dfs(depth
+1,now+1);
            row[i]
=col[i]=false;
        }
}

int main()
{
    
//freopen("data.in","r",stdin);
    
    
while(scanf("%d%d",&n,&k)==2 && (n!=-1 || k!=-1))
    {
        
for(int i=1;i<=n;i++)
        {
            getchar();
            
for(int j=1;j<=n;j++)
            {
                
char ch;
                scanf(
"%c",&ch);
                
if(ch=='#')
                    g[i][j]
=true;
                
else
                    g[i][j]
=false;
            }
        }
        
        ans
=0;
        memset(row,
false,sizeof(row));
        memset(col,
false,sizeof(col));
        dfs(
1,0);
        
        cout
<<ans<<endl;
    }
    
    
return 0;
}
posted on 2011-08-06 09:45 lee1r 阅读(417) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:搜索

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理