KY98 棋盘游戏

DFS 深搜板子
ti

#include<bits/stdc++.h>

using namespace std;

#define ll long long

struct Node {
   
    int m, n;
};

int n;
int res = 100010;
int v[6][6];
int a, b, c, d;
bool st[6][6];
ll pp[6][6];
int xi[4] = {
   1, 0, -1, 0};
int yi[4] = {
   0, 1, 0, -1};

void dfs(int x, int y, int state, int cow){
   
	if(x == c && y == d){
   
		res = min(res, cow);
		return ;
	}
	if(cow > res) return ;
	st[x][y] = true;  //防止搜回去 
	for(int i = 0; i < 4; i ++ ){
   
		int xx = x + xi[i];
		int yy = y + yi[i];
		if(xx < 0 || xx > 5 || yy < 0 || yy > 5 || st[xx][yy]) continue;
		int c = v[xx][yy] * state;
		int iu = (c % 4) + 1;
		dfs(xx, yy, iu, cow + c);
		st[xx][yy] = false;
	}
}

int main() {
   
    for(int i = 0; i < 6; i ++ ){
   
		for(int j = 0; j < 6; j ++ ){
   
			cin>>v[i][j];
		}
	}
	memset(st, 0, sizeof st);
	cin>>a>>b>>c>>d;
	dfs(a, b, 1, 0);
	cout<<res<<endl;
    return 0;
}

相关推荐

  1. KY98 棋盘游戏

    2024-01-29 14:26:02       55 阅读
  2. C语言之三子棋游戏(棋盘)

    2024-01-29 14:26:02       53 阅读
  3. 用python实现一个五子棋游戏棋盘大小是20x20

    2024-01-29 14:26:02       23 阅读
  4. KY132 xxx定律

    2024-01-29 14:26:02       57 阅读
  5. KY43 全排列

    2024-01-29 14:26:02       56 阅读
  6. KY104 Pre-Post

    2024-01-29 14:26:02       64 阅读
  7. KY199 查找

    2024-01-29 14:26:02       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-29 14:26:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-29 14:26:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-29 14:26:02       82 阅读
  4. Python语言-面向对象

    2024-01-29 14:26:02       91 阅读

热门阅读

  1. 图的邻接矩阵表示

    2024-01-29 14:26:02       55 阅读
  2. Python运算符:从入门到精通,探索无限可能!

    2024-01-29 14:26:02       40 阅读
  3. 计算机网络之ARP协议

    2024-01-29 14:26:02       60 阅读
  4. stm32 - SPI

    2024-01-29 14:26:02       58 阅读
  5. qt学习:http+访问百度智能云api实现人脸识别

    2024-01-29 14:26:02       59 阅读
  6. 77.Go中interface{}判nil的正确姿势

    2024-01-29 14:26:02       42 阅读
  7. 设计一个分布式ID

    2024-01-29 14:26:02       48 阅读