2024年6月16日 18:10,cnblog博客园的第一天!!!

终于A了 P06614迷宫游戏5,原来是动态规划......

点击查看代码
#include<bits/stdc++.h>
#define debug(a); cout<<#a<<"="<<a<<endl;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pep(i,a,b) for(int i=a;i>=b;i--) 
using namespace std;
int n;
int m;
int t;
int r1,c1,r2,c2;
char mapp[1010][1010];
int dtgh[110][110][110];
int xx[5]={0,1,0,-1,0};
int yy[5]={0,0,1,0,-1};
struct node
{
  int x;
  int y;
  int ans;
  node(int x1,int y1,int ans1)
  {
    x=x1;
	y=y1;
	ans=ans1; 	
  } 	
};
int mgbfs()
{
  queue<node> q;
  q.push(node(r1,c1,0));
  while(!q.empty())
  {
    node now=q.front();
    q.pop();
	if(now.ans>t) continue;
	rep(i,1,4)
	{
	  int r=now.x+xx[i];
	  int c=now.y+yy[i];
	  if(r>=1&&r<=n&&c>=1&&c<=m&&mapp[r][c]!='*')
	  {
	    dtgh[r][c][now.ans+1]+=dtgh[now.x][now.y][now.ans];
		if(dtgh[r][c][now.ans+1]-dtgh[now.x][now.y][now.ans]>0) 
		{
		  continue;	
		}
		q.push(node(r,c,now.ans+1));	
	  }	
	}	
  }	
  return dtgh[r2][c2][t];
}
int main()
{
  cin>>n>>m>>t;
  rep(i,1,n)
  {
  	rep(j,1,m)
	{
	  cin>>mapp[i][j];
	}
  }
  cin>>r1>>c1>>r2>>c2;
  dtgh[r1][c1][0]=1;
  cout<<mgbfs();
  return 0;	
}
今天打算写一两道dp,希望能达成目标! #C 避开水坑; #D 数位差;
posted @   OI_LuoCR  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示