当前位置:网站首页>Niuke monthly race 14- simple counting
Niuke monthly race 14- simple counting
2022-06-12 01:44:00 【Lovely and beautiful girl】
The question :
It's for you. n A little bit , Just started in the 1 spot , Then I asked you what you were doing k Days come back 1 spot , You can walk freely in the middle , But there can't be two adjacent days with the same point . How many options do you have , And take the mold .
reflection :
At the beginning, I thought about it and pushed it. I couldn't push it out , Then I thought dp, How about this one dp There are two states dp[i][0] On behalf of i Days and not 1 Number point ,dp[i][1] On behalf of i The day is at the first point , So the transfer is dp[i][0] = dp[i-1][1](n-1)+dp[i-1][0](n-2),dp[i][1] = dp[i-1][0]; If the title is given k The relatively small , Then you can do , however k It's too big , So we need to use matrix acceleration .
Code :
Matrix acceleration :
ll n,k;
ll dp[2][2];
ll a[2][2];
ll res[2][2];
ll tmp[2][2];
void mul(ll (&v1)[2][2],ll (&v2)[2][2]){
rep(i,0,2){
rep(j,0,2){
tmp[i][j] = 0 ;
rep(k,0,2){
(tmp[i][j]+=v1[i][k]*v2[k][j])%=MOD;
}
}
}
rep(i,0,2){
rep(j,0,2){
v1[i][j]=tmp[i][j];
}
}
}
void mi(int m){
a[0][0] = 0;
a[0][1] = 1;
a[1][0] = n-1;
a[1][1] = n-2;
res[0][0]=1;
res[0][1]=0;
res[1][0]=0;
res[1][1]=1;
while(m){
if(m%2){
mul(res,a);
}
mul(a,a);
m/=2;
}
}
int main(){
cin>>n>>k;
mi(k);
cout<<res[0][0]<<endl;
return 0;
}
summary : Think more and summarize .
边栏推荐
- Point cloud perception algorithm interview knowledge points (I)
- Redis cluster + sentinel mode + replicas
- Dataset how to use dataset gracefully. After reading this article, you can fully understand the dataset in c7n/choerodon/ toothfish UI
- [n32g457] remote monitoring of graffiti cloud based on RT thread and n32g457
- Basic use of MATLAB
- Pyinstaller packaging Exe (detailed tutorial)
- 联调这夜,我把同事打了...
- The 14th five year plan and investment feasibility study report of global and Chinese hydraulic ester base oil industry 2022 ~ 2028
- Don't write about the full screen explosion, try the decorator mode, this is the elegant way!!
- Bracket generation (backtracking)
猜你喜欢

I'm fired because I can only test basic functions····

In depth description of Weibull distribution (1) principle and formula

初探性能优化!从2个月到4小时的性能提升!

如何最大化的利用各种匹配方式? ——Google SEM

In depth description of Weibull distribution (2) meaning of parameters and formulas

西南林业大学“西林链”通过工信部电子标准院功能测试 | FISCO BCOS案例

Design practice of rongyun Im on electron platform

如何让杀毒软件停止屏蔽某个网页?以GDATA为例

Data in the assembly cannot start with a letter! 0 before the beginning of a letter

New knowledge: monkey improved app crawler
随机推荐
小程序111111
Redis集群更换节点IP后如何恢复集群并保留完整集群数据
[project training] wechat official account to obtain user openid
JSON conversion: entity classes and jsonobject are converted to each other, and list and jsonarray are converted to each other (fastjson version)
Detailed explanation and examples of common parameters of curl
kali安装empire过程中遇到的各种报错解决方案
【科普视频】到底什么是透镜天线?
UoE UG2 Inf Course Research
[project training] JWT
Three times a day (in serial...)
Websocket is closed after 10 seconds of background switching
PCA from 0 to 1
Agile v.s. Waterfall
Ce soir - là, j'ai battu mon collègue...
Redis实现消息队列的4种方案
"It's safer to learn a skill!" The little brother of Hangzhou campus changes to software testing, and likes to mention 10k+ weekend!
php安全开发 13博客系统的栏目模块的编写
A summary of the interface automation test problems most easily encountered
php安全开发 12博客系统的 系统模块信息的修改
The role of MOV ah, 4CH int 21