hdu 1364 Illusive Chase

7 篇文章 0 订阅
刚开始我还很怀疑我的想法,后来百度没发现题解,看到discuss里面说数据很弱,于是我就大胆的写了个暴力,每次枚举一个点找到一次到合法终点的合法
路径是,结束dfs,简单暴力代码如下
#include <iostream>
#include<cstdio>
#include<cstring>

using namespace std;
const int mx=111;
int mp[mx][mx],T,n,m,num,ans;
bool used[mx][mx];
int dx[]={0,0,1,-1},dy[]={-1,1,0,0};
struct MOVE
{
    int least,most,dir;
}mov[1000];
bool dfs(int x,int y,int co,int step)
{
    if(step==num)
    {
        return true;
    }
    if(co>=mov[step].least&&co<=mov[step].most)
    {
        if(dfs(x,y,0,step+1))
            return true;
    }
    if(co<mov[step].most)
    {
        int nx=x+dx[mov[step].dir],ny=y+dy[mov[step].dir];
        if(nx>=0&&nx<n&&ny>=0&&ny<m&&mp[nx][ny]==0)
        if(dfs(nx,ny,co+1,step))
            return true;
    }
    return false;
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
            scanf("%d",&mp[i][j]);
        num=0;
        while(scanf("%d%d",&mov[num].least,&mov[num].most),mov[num].least||mov[num].most)
        {
            char c;
            cin>>c;
            if(c=='R')mov[num++].dir=1;
            else if(c=='L') mov[num++].dir=0;
            else if(c=='U') mov[num++].dir=3;
            else mov[num++].dir=2;
        }
        ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(mp[i][j]==0)
                {

                if(dfs(i,j,0,0))ans++;
                }

            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值