一名苦逼的OIer,想成为ACMer

Iowa_Battleship

洛谷1002 过河卒

原题链接

\(DP\)水题。
还有哪个zz打上去的高精标签,害我还敲了一波高精。。

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 23;
bool v[N][N];
int mo_x[8] = { 1, 2, 2, 1, -1, -2, -2, -1 }, mo_y[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
ll f[N][N];
int main()
{
	int i, j, n, m, x, y, xx, yy;
	scanf("%d%d%d%d", &n, &m, &x, &y);
	for (n++, m++, x++, y++, i = 0; i < 8; i++)
	{
		xx = x + mo_x[i];
		yy = y + mo_y[i];
		if (xx > 0 && xx <= n && yy > 0 && yy <= m)
			v[xx][yy] = 1;
	}
	v[x][y] = 1;
	f[1][1] = 1;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
			if (!v[i][j])
			{
				if (i - 1 > 0 && !v[i - 1][j])
					f[i][j] = f[i][j] + f[i - 1][j];
				if (j - 1 > 0 && !v[i][j - 1])
					f[i][j] = f[i][j] + f[i][j - 1];
				if (i + 1 <= n && !v[i + 1][j])
					f[i][j] = f[i][j] + f[i + 1][j];
				if (j + 1 <= m && !v[i][j + 1])
					f[i][j] = f[i][j] + f[i][j + 1];
			}
	printf("%lld", f[n][m]);
	return 0;
}

posted on 2018-12-05 21:08  Iowa_Battleship  阅读(132)  评论(0编辑  收藏  举报

导航