poj1321

题目链接

#include
#include
#include
#include
#include
using namespace std;
int n,k,ans;
char m[9][9];
bool c[9];
//int dx[4]={0,-1,0,1};
//int dy[4]={-1,0,1,0};
void dfs(int depth,int exist)
{
    if(exist==k)
    {
        ans++;
        return ;
    }
    if(depth==n)
        return ;
    for(int i=0;iif(m[depth][i]=='#'&&c[i]==false)
        {
            c[i]=true;
            dfs(depth+1,exist+1);
            c[i]=false;
        }
    }
    dfs(depth+1,exist);
}
int main()
{
    while(cin>>n>>k&&(n!=-1)&&(k!=-1))
    {
        for(int i=0;icin>>m[i];
        ans=0;
        memset(c,false,sizeof(c));
        dfs(0,0);
        cout<return 0;
}

你可能感兴趣的:(递归与回溯)