2 条题解
-
1邓梓昊 LV 7 @ 2024-12-17 13:34:21
#include <iostream> #define int long long using namespace std; const short dir[8][2] = { {1 , 2} , {1 , -2} , {2 , 1} , {2 , -1} , {-1 , 2} , {-1 , -2} , {-2 , 1} , {-2 , -1} }; bool d[30][30]; int dp[30][30] , n , m , x , y; signed main(){ cin >> n >> m >> x >> y; d[x][y] = 1; for(int i = 0 ; i < 8 ; i++){ int tx = x + dir[i][0],ty = y + dir[i][1]; if(tx >= 0 && tx <= n && ty >= 0 && ty <= m) d[tx][ty] = 1; } dp[0][0] = 1; for(int i = 0 ; i <= n ; i++) for(int j = 0;j <= m;j++) if(!d[i][j]){ if(i) dp[i][j] += dp[i-1][j]; if(j) dp[i][j] += dp[i][j-1]; } cout << dp[n][m] << endl; return 0; }
-
02022-8-13 21:05:36@
#include <iostream> using namespace std; long long dp[25][25]; int xx[9] = {0,1,1,2,2,-1,-1,-2,-2}; int yy[9] = {0,-2,2,1,-1,2,-2,1,-1}; bool b[25][25]; int main(){ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; for (int i = 0;i<=8;i++){ if (x2+xx[i] < 0 or y2+yy[i] < 0){ continue; } b[x2+xx[i]][y2+yy[i]] = true; dp[x2+xx[i]][y2+yy[i]] = 0; } for (int i = 0;i<=x1;i++){ for (int j = 0;j<=y1;j++){ if (b[i][j] == true) continue; else if (i == 0 and j == 0) dp[i][j] = 1; else if (i == 0) dp[i][j] = dp[i][j-1]; else if (j == 0) dp[i][j] = dp[i-1][j]; else dp[i][j] = dp[i-1][j] + dp[i][j-1]; } } cout << dp[x1][y1]; return 0; }
- 1
信息
- ID
- 1742
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 260
- 已通过
- 63
- 上传者