http://codevs.cn/problem/1219/
此题,首先的想法是递归,但是不幸运的是超时了。
看了下题目的分类,找到了突破口。
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long ditu[60][60] = {0};
int n, m, a, b, c, d;
cin >> n >> m >> a >> b >> c >> d;
ditu[a][b] = 1;
for (int i = a + 1; i <= c; i++)
for (int j = 1; j <= m; j++)
{
if (1 <= i - 2 && j + 1 <= m)
ditu[i][j] = ditu[i - 2][j + 1];
if (1 <= i - 2 && j - 1 >= 1)
ditu[i][j] += ditu[i - 2][j - 1];
if (1 <= i - 1 && j + 2 <= m)
ditu[i][j] += ditu[i - 1][j + 2];
if (1 <= i - 1 && j - 2 >= 1)
ditu[i][j] += ditu[i - 1][j - 2];
}
cout << ditu[c][d] << endl;
return 0;
}