lanqiao 19712 数字接龙

This commit is contained in:
2025-04-11 09:28:12 +08:00
parent 35658f092a
commit 01e55f3cf7

View File

@@ -29,6 +29,7 @@ void dfs(int x, int y, int pre, string s, int dep){
if((a[bx][by] < k && a[bx][by] == pre + 1) || (pre + 1 == k && a[bx][by] == 0)){ if((a[bx][by] < k && a[bx][by] == pre + 1) || (pre + 1 == k && a[bx][by] == 0)){
vis[bx][by] = 1; vis[bx][by] = 1;
dfs(bx, by, a[bx][by], s + to_string(i), dep + 1); dfs(bx, by, a[bx][by], s + to_string(i), dep + 1);
// 最优性剪枝 // 最优性剪枝
if(!res.empty()) return; if(!res.empty()) return;
vis[bx][by] = 0; //回溯 vis[bx][by] = 0; //回溯
@@ -51,7 +52,7 @@ int main() {
return 0; return 0;
} }
/* test samples /* test samples -> 41255214
3 3 3 3
0 2 0 0 2 0
1 1 1 1 1 1