问题:输出0,调试发现处理函数core()运行后没有效果。思路:标记每个点走到的方法的种数,m[i][j]=m[i−1][j]+m[i][j−1]
注意: h[]数组没用,里面有一个debug()函数供调试。
代码:
#include <iostream>
#include <iomanip>
using namespace std;
int nx, mx;
int hx, hy;
bool h[11][2];
int m[22][22];
void init() {
m[hx][hy] = -1;
m[hx - 1][hy - 2] = -1;
m[hx + 1][hy - 2] = -1;
m[hx - 1][hy + 2] = -1;
m[hx + 1][hy + 2] = -1;
m[hx - 2][hy + 1] = -1;
m[hx - 2][hy - 1] = -1;
m[hx + 2][hy + 1] = -1;
m[hx + 2][hy - 1] = -1;
return;
}
bool find_pos(int x, int y) {
return (m[x][y] == -1);
}
void core() {
for(int i = 0; i <= nx; i ++) {
for(int j = 0; j <= mx; j ++) {
if(! find_pos(i, j)) {
if((i != 0) && (j != 0)) {
m[i][j] = m[i - 1][j] + m[i][j - 1];
}
else if((i == 0) && (j == 0)) {
m[i][j] = 0;
}
else if((i != 0) && (j == 0)) {
m[i][j] = m[i - 1][j];
}
else if((i == 0) && (j != 0)) {
m[i][j] = m[i][j - 1];
}
if((m[i - 1][j] == -1) || (m[i][j - 1] == -1)) {
m[i][j] = 0;
}
}
else {
m[i][j] = -1;
}
}
}
return;
}
void debug() {
cout << setw(8);
for(int i = 0; i <= nx; i ++) {
for(int j = 0; j <=mx; j ++) {
cout << m[i][j] << setw(8);
}
cout << endl;
}
return;
}
int main() {
cin >> nx >> mx >> hx >> hy;
init();
//debug();
core();
//cout << endl;
//debug();
cout << m[nx][mx] << endl;
return 0;
}