求助!我的做法为什么是对的?
查看原帖
求助!我的做法为什么是对的?
700558
williamwei楼主2025/6/14 16:30
#include <iostream>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 11;
int qpow(int a, int b) {
    int res = 1; for (; b; b >>= 1, a = (ll)a * a % mod)
        if (b & 1) res = (ll)res * a % mod; return res;
}
int calc(int p, int q) {return (ll)p * qpow(q, mod - 2) % mod;}
int n, k, ans;
struct Matrix {
    int a[N][N]{};
    Matrix operator*(const Matrix& b) const {
        Matrix c;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                for (int k = 1; k <= n; k++)
                    c.a[i][j] = (c.a[i][j] + (ll)a[i][k] * b.a[k][j]) % mod;
        return c;
    }
} x, y;
int main() {
    ios::sync_with_stdio(false);
    long long t; cin >> n >> t >> k;
    for (int i = 1; i <= n; i++) 
        x.a[i][i - 1] = calc(i * (i - 1), n * n), 
        x.a[i][i] = calc(n * n - i * (i - 1), n * n);
    y = x; --t; for (; t; t >>= 1, x = x * x) if (t & 1) y = y * x;
    for (int i = k; i <= n; i++) ans = (ans + y.a[n][i]) % mod;
    cout << ans << '\n';
    return 0;
}
2025/6/14 16:30
加载中...