帮忙分析下时间复杂度
深度优先搜索:(加一些分析过程,不要直接给出结果,谢谢)#include <stdio.h>
int Bx,By,Mx,My;
long long ans;
const int d={-2,-1,-1,-2,1,-2,2,-1,2,1,1,2,-1,2,-2,1};
void DFS(int x,int y){
int i;
if(x==Bx+1||y==By+1) return;
for(i=0;i<8;i++)
if(x+d==Mx&&y+d==My) return;
if(x==Mx&&y==My) return;
if(x==Bx&&y==By){
ans++;
return;
}
DFS(x+1,y);
DFS(x,y+1);
return;
}
int main(){
scanf("%d%d%d%d",&Bx,&By,&Mx,&My);
DFS(0,0);
printf("%lld",ans);
return 0;
} 原题:https://www.luogu.com.cn/problem/P1002
页:
[1]