Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:DFS一次AC，附代码

Posted by wydysbd at 2018-05-27 15:45:39 on Problem 1321
In Reply To:Re:DFS一次AC，附代码 Posted by:heyukai at 2018-03-10 15:50:00
```> #include<iostream>
> #include<cstdio>
> #include<cstring>
> #define maxn 10
> using namespace std;
> int n,k,ans;bool a[maxn][maxn],b[maxn];
> {
> 	bool f=0;char ch=getchar();
> 	while (ch<'0'||ch>'8') f^=!(ch^45),ch=getchar();
> 	return f? (~(ch^48))+1:ch^48;
> }
> inline bool fchar()
> {
> 	char ch=getchar();
> 	while (ch^'#'&&ch^'.') ch=getchar();
> 	return ch^'.';
> }
> void DFS(int l,int stp)
> {
> 	if (stp==k){ans++;return;}
> 	for (int i=l+1;i<=n;i++)
> 	  for (int j=1;j<=n;j++) if (a[i][j]&&!b[j])
> 		b[j]=1,DFS(i,stp+1),b[j]=0;
> }
> int main()
> {
> 	{
> 		memset(a,0,sizeof(a));memset(b,0,sizeof(b));ans=0;
> 		for (int i=1;i<=n;i++)
> 		  for (int j=1;j<=n;j++) a[i][j]=fchar();
> 		DFS(0,0);
> 		printf("%d\n",ans);
> 	}
> 	return 0;
> }
```

Followed by: