到底为什么过不去啊?第三四个测试过不去
查看原帖
到底为什么过不去啊?第三四个测试过不去
1384639
ouhuangxiaole楼主2024/7/8 18:44
#include <bits/stdc++.h> 
using namespace std;

class Solution {
private:
    using point = pair<int, int>;
    vector<vector<int>> dirs = {
        {1, 2}, {1, -2}, {2, 1}, {2, -1}, 
        {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}
    };
    void print(vector<vector<int>>& dp) {
		for (vector<int>& vec : dp) {
			for (int x : vec) 
				cout << x << " ";
			cout << endl;
		}
	}
public:
    int function(int n, int m, int x, int y) {
        set<point> Hash = { make_pair(x, y) };
        for (vector<int>& v : dirs) {
            const int nx = x + v[0], ny = y + v[1];
            if (nx >= 0 && nx <= n && ny >= 0 && ny <= m)
                Hash.insert(make_pair(nx, ny));
        }
        vector<vector<int>> dp(n + 1, vector<int>(m + 1));
        dp[0][0] = 1;
        for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				if (Hash.count({i, j}))
					continue;
				if (i)
					dp[i][j] += dp[i - 1][j];
				if (j)
					dp[i][j] += dp[i][j - 1];
			}
		}
        // print(dp);
        return dp[n][m];
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n, m, x, y;
    cin >> n >> m >> x >> y;

    cout << Solution().function(n, m, x, y);
    return 0;    
}
2024/7/8 18:44
加载中...