bzoj1616

水水啊,直接搜就行,不过bfs好像会mle(一定是我太菜了QAQ)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;  
const int Mx=110;
int n,m,t,ans,x1,y1,x2,y2,map[Mx][Mx]; 
void dfs(int dep,int x,int y)  
{  
    if(map[x][y]==0) return ;
    if(dep==t+1)  
    {  
        if(x==x2&&y==y2) ans++;  
        return ;
    }  
    if(abs(x-x2)+abs(y-y2)>t-dep+1) return ;
    dfs(dep+1,x-1,y);
    dfs(dep+1,x+1,y);
    dfs(dep+1,x,y-1);
    dfs(dep+1,x,y+1);
}  
int main()  
{  
    scanf("%d%d%d",&n,&m,&t);  
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;)
        {
            char ch;scanf("%c",&ch);
            if(ch=='.'||ch=='*')
            {
                if(ch=='.') map[i][j]=1;
                j++;
            }
        }
    }
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    dfs(1,x1,y1);  
    cout<<ans<<endl; 
    return 0;  
}
原文地址:https://www.cnblogs.com/xiaoxubi/p/6148063.html