题目传送门

题意:

一个魔法水晶可以分裂成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. python 文件夹下文件及文件夹名称获取

    import os dirct = 'D:/data' dirList=[] fileList=[] files=os.listdir(dirct) #文件夹下所有目录的列表 print('files ...

  2. HTML和CSS实现图片翻转效果

    实现图片翻转,首先来分析一下我们希望实现的是怎样的翻转效果?又该如何去实现呢? 一.希望实现的效果 页面上的图片在光标悬停在上面的时候会发生翻转效果,翻转过后显示出背面的说明文字. 鼠标没有悬停在上面 ...

  3. Comet OJ - Contest #6 D. 另一道树题 并查集 + 思维 + 计数

    Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...

  4. 【FJ省队训练&&NOIP夏令营】酱油&&滚粗记

    FJOI2016省队训练滚粗记 2016.07.03~2016.07.06(Day1~5) 在学校期末考.因为才省选二试too young too simple爆蛋了所以下半个学期只能滚回去读文化课, ...

  5. Leetcode 2. Add Two Numbers(指针和new的使用)结构体指针

    ---恢复内容开始--- You are given two non-empty linked lists representing two non-negative integers. The di ...

  6. 改变input的placeholder字体颜色

    改变input的placeholder字体颜色,注意哦,只是placeholder的字,用户输入的字不可以 input::-webkit-input-placeholder{ coloc:#000; ...

  7. Spring Cloud架构教程 (七)消息驱动的微服务(核心概念)【Dalston版】

    下图是官方文档中对于Spring Cloud Stream应用模型的结构图.从中我们可以看到,Spring Cloud Stream构建的应用程序与消息中间件之间是通过绑定器Binder相关联的,绑定 ...

  8. RAC & MVVM 学习资料整理

    最后更新:2017-01-23 参考链接: MVVM奇葩说 MVVM 介绍 Model-View-ViewModel for iOS [译] 唐巧--被误解的 MVC 和被神化的 MVVM React ...

  9. TypeScript快速笔记(二)

    1) TypeScript中的判断语句,可以使用非0值代表true.如: function add1(a: number, b?:number): number{ // 注意b是可选参数 consol ...

  10. ThinkPHP框架实现rewrite路由配置

    rewrite路由形式:   //网址/分组/控制器/方法 配置实现rewrite路由的配置: 1. 修改apache的配置 先修改httpd.conf配置文件中的AllowOverrideAll,全 ...