题目传送门

题意:

一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7)

思路:

线性dp,dp[i]=dp[i]+dp[i-m];

由于n到1e18,所以要用到矩阵快速幂优化

注意初始化

代码:

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define MAX 105
const int N=;//矩阵的大小
int T;
ll n,m;
ll add(ll a,ll b)
{
a%=mod;
b%=mod;
return (a+b)%mod;
}
struct hh
{
ll ma[N][N];
}a,res;
hh multi(hh a,hh b)
{
hh tmp;
memset(tmp.ma,,sizeof(tmp.ma));
for(int i=;i<N;i++)
for(int j=;j<N;j++)
for(int k=;k<N;k++)
{
tmp.ma[i][j]=add(tmp.ma[i][j],a.ma[i][k]*b.ma[k][j]);
}
return tmp;
}
void fast_pow(hh a,long long k)
{
memset(res.ma,,sizeof(res.ma));
for(int i=;i<N;i++)res.ma[i][i]=;
while(k>)
{
if(k&) res=multi(res,a);
a=multi(a,a);
k>>=;
}
}
int main()
{
while(~scanf("%lld%d",&n,&m))
{
for(int i=;i<=m;i++) a.ma[i][i-]=;
a.ma[][]=a.ma[][m]=;
fast_pow(a,n);
printf("%lld\n",res.ma[][]);
}
return ;
}

Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  4. Educational Codeforces Round 60 (Rated for Div. 2)

    A. Best Subsegment 题意 找 连续区间的平均值  满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...

  5. Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

    #include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...

  6. Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)

    #include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size() ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) 即Codeforces Round 1117 C题 Magic Ship

    time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String

    题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...

  9. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题

    B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...

随机推荐

  1. Linux kswapd0 进程CPU占用过高

    图便宜买了个1核1G虚拟机,启动两个jar后cpu飙升直接卡死,查看cpu及内存占用 发现kswapd0进程cpu占用一直居高不下,于是查询资料,总结如下. swap分区的作用是当物理内存不足时,会将 ...

  2. 对postcss以及less和sass的研究

    1.postcss PostCSS 的主要功能只有两个:第一个就是前面提到的把 CSS 解析成 JavaScript 可以操作的 抽象语法树结构(Abstract Syntax Tree,AST),第 ...

  3. HTTP content-type及POST提交数据方式

    Content-Type(内容类型),一般指网页中存在的Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式.什么编码读取这个文件,这也是一些网页点击的结果却是一个文件 ...

  4. linux运维、架构之路-禅道环境搭建

    一.介绍            禅道项目管理软件是国产的开源项目管理软件,专注研发项目管理,内置需求管理.任务管理.bug管理.缺陷管理.用例管理.计划发布等功能,实现了软件的完整生命周期管理. 禅道 ...

  5. Xcode 代码注释

    /** * 生成二维码 * * @param data 二维码数据 * @param size 二维码大小 * @param color 二维码颜色 * @param backgroundColor ...

  6. P1092 虫食算——题解

    题目传送 (据说官方正解为高斯消元,但用搜索也能过,这里就讲讲搜索算法吧.) 对于一道搜索题,首先考虑一下大体怎样搜索.因为要考虑加法的进位,所以从左往右搜索对于考虑进位来说十分麻烦,而从右往左搜索就 ...

  7. Linux相关基础知识

    文件目录 /bin 放置系统执行档的目录,指令可被root与一般账户所使用. /boot 放置开机使用到的文档,包括linux核心档案,开机选单与所需设定档. /dev 任何装置与周边设备都是以档案的 ...

  8. NSDate 那点事

    转载自:http://my.oschina.net/yongbin45/blog/150114 NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是N ...

  9. 微信小程序之登录用户不是该小程序的开发者

    当uniapp项目转为小程序项目的时候,预览会显示“您不是登录用户...”,所以没有办法发布,这个时候打开“project.config.json”设置一下appid,与你公众号appid一致就可以

  10. 查看Linux中lanmp的各软件编译参数

    转载 如何查看已经安装的nginx.apache.mysql和php的编译参数 Mysql查看mysql编译参数 Mysql5.4及之前版本查看编译安装参数,进入到mysql安装目录的bin下面 $ ...