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 ...
随机推荐
- 关于在IOS中 contenteditable=true 无法输入的问题
解决: 1.添加样式-webkit-user-select:text 2.如果引入了fastclick,需要添加个类名 needsclick 来源于知乎(https://www.zhihu.com/q ...
- POJ1523 SPF 单点故障
POJ1523 题意很简单,求删除割点后原先割点所在的无向连通图被分成了几个连通部分(原题说prevent at least one pair of available nodes from bein ...
- vueroute的router.addRoutes
router.addRoutes(routes: Array<RouteConfig>)动态添加更多路由到路由器.参数必须是使用与routes构造函数选项相同的路径配置格式的Array .
- Eclipse搭建Maven项目并上传SVN备份
本文出自:http://www.cnblogs.com/2186009311CFF/p/7226127.html 背景:近段时间在学着Java,想着用Java做BS的项目.但是项目一遇到问题又要重做, ...
- VS2019界面透明、主题修改和导出设置
目录 安装插件Color Theme Editor for Visual Studio 2019和ClaudiIDE 导入主题 背景修改 效果预览 导出设置遇到错误924 其他帮助文档 我自己用的主题 ...
- Internet History, Technology, and Security(week7)——Technology: Application Protocols
Layer 4: Applications Application Layer TCP提供了“a reliable pipe”(一个坚固的水管)连接用户和服务器,确保了数据能准确不出意外地传输,所以A ...
- spring bean.xml
http://blog.csdn.net/lanshengsheng2012/article/details/9011635
- Taylor Swift -《Fearless》
最近网上都搜不到Taylor的歌了,分享一张love best的album给大家,支持霉霉的还是去买正版把~ 专辑曲目: 01. “Jump Then Fall” 03:5702. “Untoucha ...
- python中导入sklearn中模块提示ImportError: DLL load failed: 找不到指定的程序。
python版本:3.7 平台:windows 10 集成环境:Anaconda3.7 64位 在jupyter notebook中导入sklearn的相关模块提示ImportError: DLL l ...
- Linux动态库和静态库
Linux下动态库查看办法:nm -D libavformat.so Linux下静态库查看办法:ar -t libavformat.a ------------------------------- ...