花园

【代码】

#include<bits/stdc++.h>

#define LL long long

using namespace std;
const int M = 5, p = 1000000007;
LL n, m, k, ans = 0;
LL f[1 << M], a[1 << M][1 << M];
int MAX, cnt;
bool pd[1 << M];
inline void mulself(LL a[1 << M][1 << M]) {
	LL c[1 << M][1 << M];
	memset(c, 0, sizeof c);
	for(int i = 0; i < MAX; ++i)
		for(int j = 0; j < MAX; ++j)
			for(int k = 0; k < MAX; ++k)
				c[i][j] = (c[i][j] + a[i][k] * a[k][j]) % p;
	memmove(a, c, sizeof c);
}
inline void mul(LL f[1 << M], LL a[1 << M][1 << M]) {
	LL c[1 << M];
	memset(c, 0, sizeof c);
	for(int j = 0; j < MAX; ++j)
		for(int k = 0; k < MAX; ++k)
			c[j] = (c[j] + f[k] * a[k][j]) % p;
	memmove(f, c, sizeof c);
}
int main() {
	scanf("%lld%lld%lld", &n, &m, &k);
	MAX = 1 << m;
	for(int i = 0; i < MAX; ++i) {
		cnt = 0;
		for(int j = 0; j < m; ++j)
			if(i & 1 << j) ++cnt;
		if(cnt <= k) pd[i] = true;
	}
	for(int i = 0; i < MAX; ++i)
		if(pd[i]) {
			memset(f, 0, sizeof f);f[i] = 1;
			memset(a, 0, sizeof a);
			for(int j = 0; j < MAX; ++j) if(pd[j]){
				a[j >> 1][j] = 1;
				a[(j >> 1) + (1 << (m - 1))][j] = 1;
			}
			for(LL y = n; y; y >>= 1, mulself(a))
				if(y & 1)
					mul(f,a);
			ans = (ans + f[i]) % p;
		}
	printf("%lld
", ans);
	return 0;
}
原文地址:https://www.cnblogs.com/kcfzyhq/p/8653746.html