View Code of Problem 450

#include<bits/stdc++.h>
using namespace std;
int g[10][10],xx[10],yy[10],n,ans;
void dfs(int x,int y,int k){
	xx[x]=1;yy[y]=1;
	if(k==1)
	ans++;
	for(int i=x+1;i<=n;++i){
		
		for(int m=1;m<=n;++m){
			
			if(g[i][m]=='#'&&xx[i]==0&&yy[m]==0)
			dfs(i,m,k-1);
		}
	}
	xx[x]=0;yy[y]=0;
}
int main(){
	int k;
	while(cin>>n>>k&&(n!=-1||k!=-1)){
		getchar();
		ans=0;
		memset(xx,0,sizeof(xx));
		memset(yy,0,sizeof(yy));
		for(int i=1;i<=n;++i){
			for(int m=1;m<=n;++m){
				scanf("%c",&g[i][m]);
			}
			getchar();
		}
		for(int i=1;i<=n;++i){
			for(int m=1;m<=n;++m)
			if(g[i][m]=='#')
				dfs(i,m,k);
		}
		cout<<ans<<endl;
	}
}
/*
Main.cc:2:24: bits/stdc++.h: No such file or directory
Main.cc: In function `int main()':
Main.cc:21: error: `cin' undeclared (first use this function)
Main.cc:21: error: (Each undeclared identifier is reported only once for each function it appears in.)
Main.cc:22: error: `getchar' undeclared (first use this function)
Main.cc:24: error: `memset' undeclared (first use this function)
Main.cc:28: error: `scanf' undeclared (first use this function)
Main.cc:37: error: `cout' undeclared (first use this function)
Main.cc:37: error: `endl' undeclared (first use this function)
*/

Double click to view unformatted code.


Back to problem 450