第十九章 ALDS1_13_C:15 Puzzle 十六格拼图

本文介绍了如何运用IDA*算法解决16格拼图(15 Puzzle)问题,通过逐步加深搜索限制来寻找从当前状态到目标状态的最短路径。内容包括问题背景、解题思路及IDAA*算法的实现代码。
摘要由CSDN通过智能技术生成

知识点

迭代加深:在循环执行深度受限搜索的过程中逐步增加限制值limit,直到找到解为止。
如果当前状态到最终状态的最小成本h加上当前状态深度超过了限制深度d,就可以直接中断搜索。

问题链接

ALDS1_13_C:15 Puzzle

问题内容

求当前16宫格如何移动成目标的16宫格。

思路

用A*或者IDA* 算法实现

代码

IDA*算法
#include<iostream>   
#include<cstdio>  
#include<algorithm>
#include<queue>
#include<map>
#include<string>
using namespace std;
const int row = 4;
const int maxx = 16;
const int LIMIT = 100;
struct Puzzle {
    int f[maxx], space, MD;
};

const int dx[4] = { 0, -1, 0, 1 };
const int dy[4] = { 1, 0, -1 ,0 };
const char dir[4] = { 'r','u','l','d' };
int MDT[maxx][maxx];

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
    int sum = 0;
    for (int i = 0; i < maxx; i++) {
        if (pz.f[i] !&#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值