[JZOJ4628] 立方体

Descripton

这里写图片描述
这里写图片描述

Solution

不要把这种题想复杂了。

这样的东西往往就是搜索。

f[x][y][q][u][l] 表示在 x,y 这个点以原来的 q 作为前面,u是上, l 是左的最小步数。

按照这个记忆化搜索,dfs带进这5个参数,四个方向直接转移状态。

P.S. 某些人十分机(sha)智(bi)的把转移的各种情况打成了表。

码量最多的有 3K ~~,据说打了一个多小时。

我这个暴力从开打到搞对不超20分钟~

Code

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fod(i,a,b) for(i=a;i>=b;i--)
using namespace std;
int a[6],f[8][8][6][6][6],sx,sy,ex,ey,ops[6],ans;
bool pd(int x,int y)
{
    return (x<=7&&y<=7&&x>=0&&y>=0); 
} 
void dfs(int x,int y,int q,int u,int l,int s)
{
    int i,x1,y1;
    if (x==ex&&y==ey)
    {
        ans=min(ans,s);
        return;
    }
    if (f[x][y][q][u][l]<=s) return;
    f[x][y][q][u][l]=s;
    x1=x+1;
    y1=y;
    if (pd(x1,y1)) dfs(x1,y1,ops[u],q,l,s+a[ops[q]]);
    x1=x-1;
    y1=y;
    if (pd(x1,y1)) dfs(x1,y1,u,ops[q],l,s+a[q]);
    x1=x;
    y1=y+1;
    if (pd(x1,y1)) dfs(x1,y1,q,l,ops[u],s+a[ops[l]]);
    x1=x;
    y1=y-1;
    if (pd(x1,y1)) dfs(x1,y1,q,ops[l],u,s+a[l]);
}
int main()
{
    char c1,c2,c3,c4,c0;
    scanf("%c%c%c%c%c",&c1,&c2,&c0,&c3,&c4);
    sx=c2-'1';
    sy=c1-'a';
    ex=c4-'1';
    ey=c3-'a';
    int i;
    fo(i,0,5) 
    {
        ops[i]=(i%2==0)?i+1:i-1;//这里表示每个面的对面是什么
    }
    scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[5],&a[3],&a[4]);
    ans=100000000;
    memset(f,107,sizeof(f));
    dfs(sx,sy,0,2,4,a[3]);
    cout<<ans;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值