[ SHOI 2015 ] 超能粒子炮·改

题目

Luogu
LOJ
Acwing

思路

001.png
002.png
003.png

代码

#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int N = 3010, p = 2333;
int T, n, m;
short c[N][N], f[N][N];
int Lucas(int a, int b) {
    if (a < p && b < p) return c[a][b];
    return Lucas(a / p, b / p) * c[a % p][b % p] % p;
}
int C(int a, int b) { return Lucas(a, b); }
int F(int n, int k) {
    if (n < p && k < p) return f[n][k];
    return (F(n % p, p - 1) * F(n / p, (k / p) - 1) % p + 
            C(n / p, k / p) * F(n % p, k % p) % p) % p;
}
signed main() {
    scanf("%d", &T);
    for (int i = 0; i <= 3000; i++)
        for (int j = 0; j <= i; j++)
            if (!j) c[i][j] = 1;
            else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;
    for (int i = 0; i <= 3000; i++)
        for (int j = 0; j <= 3000; j++)
            if (!j) f[i][j] = 1;
            else f[i][j] = (f[i][j - 1] + c[i][j]) % p;
    while (T-- && scanf("%lld%lld", &n, &m)) printf("%d\n", F(n, m));
    return 0;
}
posted @ 2021-06-17 16:19  Protein_lzl  阅读(45)  评论(0编辑  收藏  举报