各位神犇帮忙看一下蒟蒻为什么TLE了
  • 板块P1784 数独
  • 楼主Phrvth
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/9/4 09:56
  • 上次更新2023/11/4 08:02:55
查看原帖
各位神犇帮忙看一下蒟蒻为什么TLE了
520544
Phrvth楼主2021/9/4 09:56

TLE代码,帮忙看看

#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int b1[10][10],b2[10][10],b3[10][10];
void show(){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	exit(0);
}
void dfc(int x){
	if(x>81){
		show();
		return;
 }
	int heng=(x-1)/9+1;
	int shu=(x-1)%9+1;
	int gong=(heng-1)/3*3+(shu-1)/3+1;
	for(int i=1;i<=9;i++){
		if(b1[heng][i]==0 and b2[shu][i]==0 and b3[shu][i]==0){
			a[heng][shu]=i;
			b1[heng][i]=1;b2[shu][i]=1;b3[gong][i]=1;
			dfc(x+1);
			b1[heng][i]=0;b2[shu][i]=0;b3[gong][i]=0;
		}
	}
}
int main(){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			cin>>a[i][j];
		}
	}
	dfc(1);
	return 0;
} 
2021/9/4 09:56
加载中...