跳到正文

个人记录

排列组合C 作者解题

wuliu21约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
1

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long q,n,m,a[3001][3001];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(long long i = 0;i <= 3000;i++){
        for(long long j = 0;j <= i;j++){
            if(i == 0 || j == i){
                a[i][j] = 1;
            }else{
                a[i][j] = (a[i - 1][j - 1] + a[i - 1][j]) % mod;
            }
        }
    }
    cin >> q;
    while(q--){
        cin >> n >> m;
        cout << a[n][m] << "\n";
    }
    return 0;
}

本题考验预处理能力,预处理CnmC_n^m的nn和mm的所有情况。

原文