请问27和29行合理吗?
(AC了,但感觉不太对orz)
原题 P1767
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
int kkk=0,f=1;char ch;ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
kkk=kkk*10+ch-'0';
ch=getchar();
}
return f*kkk;
}
int book[55]={},ne[25][3],n,a,ans=0;
void dfs(int now){
if(now==n+1){
ans++;
}
else{
book[ne[now][1]]--;
if(book[ne[now][1]]>=1)dfs(now+1);
book[ne[now][1]]++;book[ne[now][2]]--;
if(book[ne[now][2]]>=1)dfs(now+1);
book[ne[now][2]]++;
}
return ;
}
int main()
{
n=read();if(n==0){printf("0");return 0;}
for(int i=1;i<=n;i++){
a=read();book[a]++;ne[i][1]=a;
a=read();book[a]++;ne[i][2]=a;
}
dfs(1);
printf("%d",ans);
return 0;
}