#include <stdio.h>
int stackrow[100];
int stackcol[100];
int ps = 0;
int count = 0;
void push(int row, int col) {
stackrow[ps] = row;
stackcol[ps] = col;
ps++;
}
void pop() {
ps--;
}
void output_result() {
count++;
int i;
printf("result %d\n", count);
for(i=0; i<ps-1; i++) {
printf("(%d,%d)->", stackrow[i], stackcol[i]);
}
printf("(%d,%d)", stackrow[ps-1], stackcol[ps-1]);
printf("\n");
};
void horse(int row, int col,int x,int y) {
push(row, col);
if(row == x && col == y)
output_result();
if(row < 0 ||col < 0|| row > x || col > y) {
;
} else {
horse(row +2, col + 1,x,y);
horse(row +1, col + 2,x,y);
horse(row + 1, col -2,x,y);
horse(row + 2, col - 1,x,y);
}
pop();
}
int main(void)
{
int i,x,y;
printf("请输入终点x y(空格分隔)");
scanf("%d %d",&x,&y);
horse(0, 0,x,y);
return 0;
}
C语言/c++解决马走日问题。:从(0,0)点到(x,y)点,只能往右,输出每种路径总数并打印出各种路径
版权申诉
5星 · 超过95%的资源 64 浏览量
2022-06-21
09:58:32
上传
评论
收藏 1KB RAR 举报
白驹_过隙
- 粉丝: 6313
- 资源: 44
- 1
- 2
- 3
前往页