Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)
题意:
一个魔法水晶可以分裂成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(矩阵快速幂)的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Educational Codeforces Round 60 (Rated for Div. 2)
A. Best Subsegment 题意 找 连续区间的平均值 满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...
- 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 ...
- 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() ...
- 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...
- 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 ...
随机推荐
- 【CF838E】 Convex Countour
[CF838E] Convex Countour 首先观察题目的性质 由于是凸包,因此不自交路径中的一条边\((x, y)\)的两端点只能向与\(x\)或\(y\)相邻的结点连边. 举个栗子,若选取了 ...
- 【NOIP2016提高A组模拟8.14】疯狂的火神
题目 火神为了检验zone的力量,他决定单挑n个人. 由于火神训练时间有限,最多只有t分钟,所以他可以选择一部分人来单挑,由于有丽子的帮助,他得到了每个人特定的价值,每个人的价值由一个三元组(a,b, ...
- nyoj 952 : 最大四边形 (计算几何)
题目链接 任意四边形均可看作是两个三角形拼接得到的(即使是凹四边形),故 可以O(n^2)枚举所有的线段,然后对每条线段O(n)枚举线段端点外的其他点,用来更新以此线段构成的三角形的有向面积的最大值m ...
- LeetCode--148--排序链表(python)
在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序. 示例 1: 输入: 4->2->1->3输出: 1->2->3->4示例 2: 输入: ...
- zrender的线性渐变
线性渐变 官方文档是这样写的 实际运用是酱紫的 在把颜色放背景中 小白一枚,路过大神,多多指教.欢迎留下宝贵意见
- RPA走专有云还是公共云?阿里云RPA公共云给出了这样几组数据…
自从近年国外UIPATH.AUTOMATION ANYWHERE.BLUE PRISM等RPA企业的崛起,Robotic Process Automation(RPA)走进了人们视野.它以节省成本.提 ...
- js解决手机键盘影响定位的问题
// 滑动其他地方隐藏软键盘document.body.addEventListener('touchend', function(evt) { document.activeElement.blur ...
- ipcloud上传裁切图片
主页: <!doctype html> <html> <head> <meta charset="utf-8"> <meta ...
- 软件工程 in MSRA 第一周博客作业
1. 自我介绍 大家好-我是陈海峰,哈尔滨工业大学计算机学院的一名大四学生,大四开始在 MSRA 的 KC 组进行实习.作为一个标准的"肥宅",对运动没什么兴趣的我,主要的兴趣点就 ...
- GeoServer-2.12安装MbTiles扩展插件