请教:洛谷P1002过河卒代码问题?-灵析社区

横刀立马007

请教代码问题。 这道题我的代码直接爆零,不理解为什么。看完题解后觉得除了dp的部分,其他的知识点都用到了,而且思路完整。下面献上本人拙劣的代码,请老师指教。 #include using namespace std; int flag[25][25];//horse control int n,m;//B location int hi,hj;//horse location int ans=0,now; void dfs(int x,int y){ if(now>n>>m>>hi>>hj; for(int i=1;i using namespace std; int ans=0; int n1,m1,n,m; void dfs(int x,int y){ if(x>n||y>m||x>n>>m>>n1>>m1; dfs(0,0); cout<

阅读量:13

点赞量:0

问AI
now 没有给初值。(你这个写法,now 其实没啥必要,直接累加 ans 就好了。你这个是个遍历,遍历一条加一条) "((i-x)*(i-x)+(j-y)*(j-y)==2)" ,这个关系是斜对角线。斜对角线没有被控制就向右向下走一格是不对的。 对 hi+2, hi-2, hj+2, hj-2 , x, y 是否走到棋盘外没有控制。