zoukankan      html  css  js  c++  java
  • 花园

    【代码】

    #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;
    }
    
  • 相关阅读:
    openresty 使用 log_by_lua 发送日志到 syslog-ng
    uuid 了解
    基于openresty 的几个开发框架
    openresty 几个插件使用
    kong 了解
    openresty && hashids&& redis 生成短链接
    kong k8s 安装 以及可视化管理界面
    hashids 了解
    Apache Tez 了解
    Cascalog了解
  • 原文地址:https://www.cnblogs.com/kcfzyhq/p/8653746.html
Copyright © 2011-2022 走看看