emmmm...据说是比较简单的dp?(再一次意识到自己的菜)
链接:https://www.luogu.com.cn/problem/P1002
题目:
总的思路就是一个状态转移方程吧:
dp[x][y] = dp[x-1][y] + dp[x][y-1];
然后如果发现这个点不能通过,那么强制修改dp[x][y] = 0;
代码:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
const int N = 22;
int xb, yb, xm, ym;
bool jd[N][N];
ll dp[N][N];
int del[][2] = { {0,0},{2,1},{2,-1},{1,2},{1,-2},{-2,1},{-2,-1},{-1,2},{-1,-2} };
ll dfs(int x, int y)
{
if (dp[x][y] != 0)return dp[x][y];
if (x < 1 or y < 1)return 0;
ll res;
if (jd[x][y])res = 0;//这个配合jd一起用
else res = dfs(x - 1, y) + dfs(x, y - 1);//核心在这里
return dp[x][y] = res;
}
int main()
{
cin >> xb >> yb >> xm >> ym;
xb++, yb++, xm++, ym++;
//init()部分修改jd,判断马能不能到
for (int i = 0; i < 9; i++)
{
int dx = del[i][0] + xm, dy = del[i][1] + ym;
if (dx >= 1 and dx <= xb and dy >= 1 and dy <= yb)
jd[dx][dy] = true;
}
dp[1][1] = 1;
cout << dfs(xb, yb);
return 0;
}
标签:过河,NOIP2002,xm,int,ll,P1002,++,include,dp
From: https://www.cnblogs.com/zzzsacmblog/p/18113635