/*dp[i][j]: = The number of paths from the starting point [0][0] to the position where the coordinates are [i][j]. Stroke rule: can be down, or to the right, so dp[i][j] = Dp[i-1][j] + dp[i][j-1] (down) (right) Note: Remove the other side of the horse's control point attached: Codevs test data is somewhat weak, you can consider here to evaluate: Clear Orange (the main difference is that the dp[][] data type is set to long long) */
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstddef>5#include <iterator>6#include <algorithm>7#include <locale>8#include <cmath>9#include <vector>Ten#include <cstring> One using namespacestd; A Const intINF =0x3f3f3f3f; - Const intMAXN = -; - Const intMAXM = -; the Const intMaxavoid =9; - - intN, m, x, y; - BOOLARR[MAXN][MAXM]; + Long LongDP[MAXN][MAXM]; - intAvoidx[maxavoid] = {0, -1, -2, -2, -1,1,2,2,1}; + intAvoidy[maxavoid] = {0, -2, -1,1,2,2,1, -1, -2}; A at - voidSolve () - { - if(!arr[0][0]) - { - //DP Initialization indp[0][0] =1; - } to for(inti =0; I <= N; ++i) + { - for(intj =0; J <= M; ++j) the { * if(!Arr[i][j]) $ {Panax Notoginseng if((I-1) >=0) Dp[i][j] + = dp[i-1][j]; - if(J-1) >=0) Dp[i][j] + = dp[i][j-1]; the } + } A } thecout << Dp[n][m] <<Endl; + } - $ intMain () $ { - -CIN >> n >> m >> x >>y; thememset (arr,0,sizeof(arr)); -Memset (DP,0,sizeof(DP));Wuyi //Remove the other horse's control points the for(inti =0; i < maxavoid; ++i) - { Wu inttx = x +Avoidx[i]; - intTy = y +Avoidy[i]; About if(TX >=0) && (TX <= N) && (Ty >=0) && (Ty <=m)) $ { -Arr[tx][ty] =true; - } - } A Solve (); + the - #ifdef HOME $Cerr <<"Time Elapsed:"<< clock ()/Clocks_per_sec <<"Ms"<<Endl; the #endif the return 0; the}
Checkerboard-type dynamic planning Code[vs] 1010 River Crossing 2002 Noip National League universal Group