一点疑问orz
  • 板块灌水区
  • 楼主Kalpas_s2006
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/11/27 18:28
  • 上次更新2023/11/3 23:26:23
查看原帖
一点疑问orz
544029
Kalpas_s2006楼主2021/11/27 18:28

请问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; 
 } 
2021/11/27 18:28
加载中...