思路:dp
首先,第i列的个数肯定和第i - n列个数一样,假设[i - n + 1, i - 1] 之间的个数之和为x,那么第i列和第i-n列的个数应该是n - x
那么我们可以用dp求方案数
状态:dp[i][j] 表是到第 i 列为止 填了 j 个的方案数
初始状态: dp[0][0] = 1
状态转移: dp[i][j](1 <= i <= n, 0 <= j <= k) = ∑(dp[i-1][j - l](l <= n && j >= l) * C(n, l) ^ cnt)
其中,cnt = n/m 或者 n/m + 1,C(n, l)^cnt 可以预处理来降低复杂度
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pii pair<int, int> #define piii pair<pii, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head const int MOD = 1e9 + 7; const int N = 110; LL dp[N][N*N]; LL qp[N][N][2]; LL q_pow(LL n, LL k) { LL ans = 1; while(k) { if(k&1) ans = (ans * n) % MOD; n = (n * n) % MOD; k >>= 1; } return ans; } int main() { int n, k; LL m; scanf("%d %lld %d", &n, &m, &k); LL cnt = m/n; LL C = 1; for (int i = 0; i <= n; i++) { qp[n][i][0] = q_pow(C, cnt); qp[n][i][1] = q_pow(C, cnt+1); C = (C * (n-i)) % MOD; C = (C * q_pow(i+1, MOD-2)) % MOD; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { for (int l = 0; l <= n && j >= l; l++) { if(i <= m%n) dp[i][j] = (dp[i][j] + dp[i-1][j-l] * qp[n][l][1]) % MOD; else dp[i][j] = (dp[i][j] + dp[i-1][j-l] * qp[n][l][0]) % MOD; } } } printf("%lld ", dp[n][k]); return 0; }