难死了!吐血:(
2026-03-22 10:41:51
发布于:浙江
链接描述
我不是被逼的
费尽心血
#include<bits/stdc++.h>
using namespace std;
int dp[6][6];
bool demp[6][6];
int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int cnt,fx,fy,sx,sy,t,n,m,l,r;
void dfs(int x,int y){
if(x==fx&&y==fy){
cnt++;
return;
}
else{
for(int i=0;i<=3;++i){
if(demp[x+dx[i]][y+dy[i]]==0&&dp[x+dx[i]][y+dy[i]]==1){
demp[x][y]=1;
dfs(x+dx[i],y+dy[i]);
demp[x][y]=0;
}
}
}
}
int main(){
cin>>n>>m>>t;
for(int ix=1;ix<=n;++ix){
for(int iy=1;iy<=m;++iy){
dp[ix][iy]=1;
}
}
cin>>sx>>sy;
cin>>fx>>fy;
for(int j=1;j<=t;j++){
cin >>l>>r;
dp[l][r]=0;
}
dfs(sx,sy);
cout<<cnt;
return 0;
}
题解
有没有更优解!
全部评论 7
为了罐头,点赞+评论
20小时前 来自 浙江
3评论顺便搞宣传
20小时前 来自 江苏
1我和“三角洲和我的世界粉都可加(群主都玩)”的小伙伴都在ACGO等你,快用这个专属链接加入我们吧!传送
20小时前 来自 江苏
1
d
10小时前 来自 浙江
0这不今天考试题目
16小时前 来自 浙江
0算法层面上似乎没有(?)但是想要跑的比你快的代码还是有的
16小时前 来自 浙江
0然而只是快读快写
16小时前 来自 浙江
0
d
17小时前 来自 四川
0#include <stdio.h> short n,m,vis[41][41],sum,sx,sy,fx,fy,zhx,zhy,t; short a[51][51],dx[]={1,-1,0,0}; short dy[]={0,0,1,-1}; void f(int x,int y){ if(x==fx&&y==fy){ sum++; return; } vis[x][y]=1; for(int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(vis[nx][ny])continue; if(nx<1||nx>n||ny<1||ny>m){ continue; } if(a[nx][ny]==1){ continue; } f(nx,ny); } vis[x][y]=0; } int main(){ scanf("%hd %hd %hd",&n,&m,&t); scanf("%hd %hd %hd %hd",&sx,&sy,&fx,&fy); for(int j=1;j<=t;j++){ scanf("%hd %hd",&zhx,&zhy); a[zhx][zhy]=1; } f(sx,sy); printf("%hd",sum); }18小时前 来自 云南
0我和“三角洲和我的世界粉都可加(群主都玩)”的小伙伴都在ACGO等你,快用这个专属链接加入我们吧!传送
20小时前 来自 江苏
0












































有帮助,赞一个