跳到正文

题解

题解:AT1202Contest_c binarydigit

hqzx2024HYC约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前

#include <bits/stdc++.h> using namespace std;

int main() { int H, W, M; cin >> H >> W >> M;

C++
vector<vector<int>> ans(H + 1, vector<int>(W + 1, 0));
vector<vector<int>> comb(H + W + 2, vector<int>(H + W + 2, 0));

// Precompute combinations modulo M using Pascal's identity
comb[0][0] = 1 % M;
for (int n = 1; n <= H + W; ++n) {
    comb[n][0] = 1 % M;
    for (int k = 1; k <= n; ++k) {
        comb[n][k] = (comb[n-1][k-1] + comb[n-1][k]) % M;
    }
}

for (int h = 1; h <= H; ++h) {
    for (int w = 1; w <= W; ++w) {
        ans[h][w] = comb[h + w][h] % M;
    }
}

for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
        cout << ans[i][j];
        if (j < W) cout << ";
    }
    cout << endl;
}

return 0;

}

原文