[codeforces821E]Okabe and El Psy Kongroo
题意:(0,0)走到(k,0),每一部分有一条线段作为上界,求方案数。
解题关键:dp+矩阵快速幂,盗个图,注意ll
关于那条语句为什么不加也可以,因为我的矩阵C,就是因为多传了了len的原因,其他位置都是0,所以不需要加

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
struct mat{
ll m[][];
}A; mat mul(mat &A,mat &B,ll len){
mat C={};
for(int i=;i<=len;i++){
for(int k=;k<=len;k++){
for(int j=;j<=len;j++){
C.m[i][j]=(C.m[i][j]+A.m[i][k]*B.m[k][j]%mod+mod)%mod;
}
}
}
return C;
} mat mod_pow(mat A,ll n,ll len){
mat B={};
for(int i=;i<=len;i++) B.m[i][i]=;
while(n>){
if(n&) B=mul(B,A,len);
A=mul(A,A,len);
n>>=;
}
return B;
} int main(){
ll n,k;
ios::sync_with_stdio();
cin.tie();
cout.tie();
for(int i=;i<;i++){
int j=i->=?i-:;
for(;j<=i+&&j<;j++){
A.m[i][j]=;
}
}
mat C;
cin>>n>>k;
mat B={};
B.m[][]=;
ll cnt=;
for(int i=;i<n&&cnt<k;i++){
ll a,b,c;
cin>>a>>b>>c;
if(b>k) b=k;
cnt+=b-a;
C=mod_pow(A, b-a, c);
B=mul(B, C, c);
for(ll j=c+;j<;j++) B.m[j][]=;//这句话不加也可以,为什么?
}
cout<<(B.m[][]+mod)%mod<<"\n";
return ;
}
[codeforces821E]Okabe and El Psy Kongroo的更多相关文章
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces 821E Okabe and El Psy Kongroo(矩阵快速幂)
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo DP+矩阵快速幂加速
E. Okabe and El Psy Kongroo Okabe likes to take walks but knows that spies from the Organization ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo dp+矩阵快速幂
E. Okabe and El Psy Kongroo Okabe likes to take walks but knows that spies from the Organization c ...
- Codeforces 821E Okabe and El Psy Kongroo
题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y-1)或者(x+1,y)或者(x+1,y+1)三个位子之一.现在一共有N段线段,每条线段都是平行于X ...
- CF821 E. Okabe and El Psy Kongroo 矩阵快速幂
LINK 题意:给出$n$条平行于x轴的线段,终点$k$坐标$(k <= 10^{18})$,现在可以在线段之间进行移动,但不能超出两条线段的y坐标所夹范围,问到达终点有几种方案. 思路:刚开始 ...
- CF821E 【Okabe and El Psy Kongroo】
首先我们从最简单的dp开始 \(dp[i][j]=dp[i-1][j]+dp[i-1][j+1]+dp[i-1][j-1]\) 然后这是一个O(NM)的做法,肯定行不通,然后我们考虑使用矩阵加速 \( ...
- 【codeforces 821E】Okabe and El Psy Kongroo
[题目链接]:http://codeforces.com/problemset/problem/821/E [题意] 一开始位于(0,0)的位置; 然后你每次可以往右上,右,右下3走一步; (x+1, ...
- codeforces E. Okabe and El Psy Kongroo(dp+矩阵快速幂)
题目链接:http://codeforces.com/contest/821/problem/E 题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y- ...
随机推荐
- JSP页面EL表达式不解析
问题是这样:在搭建springMVC环境的时候,笔者写了一个简单的Controller如下: @Controller public class HelloController { @RequestMa ...
- linux操作系统使用中的一些总结
VIM常用命令 gg //到第一行 (N)G //到第n行(N为整数) G //到最后一行 0 //到行头 $ //到行尾 (N)dd //删除N行,并将内容保存到粘贴板 p ...
- [原创]java WEB学习笔记18:java EE 中的MVC 设计模式(理论)
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- mysql管理工具之pt-heartbeat
之前我一直用Seconds_behind_master来衡量主从的延迟,今天看到文档,才觉得多么不可靠!以下是官方文档的描述: In essence, this field measures the ...
- developerWorks 图书频道: 深入分析 Java Web 技术内幕,第 10 章
developerWorks 图书频道: 深入分析 Java Web 技术内幕,第 10 章 深入理解 Session 与 Cookie Session 与 Cookie 不管是对 Java Web ...
- Win7.窗口自动滚动回到屏幕
PS:笔记本 ThinkPad E440 1.前提:窗口 的一部分位于在屏幕的外面,此窗口处于激活的状态 操作:鼠标放置在窗口内部,鼠标继续往屏幕外部移动,鼠标没有任何其他事件(只有 MouseMov ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏:dfs【无根树 节点分枝子树大小】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3391 题意: 给你一棵无根树,求分支size均不大于一半点数的点. 题解: 假定1为根. ...
- GridView内容详解(转载)
GridView内容详解(转载) GridView是ASP.NET界面开发中的一个重要的控件,对GridView使用的熟练程度直接影响软件开发的进度及功能的实现.(车延禄)GridView的主要新特性 ...
- Oracle学习笔记_03_单行函数
1.SQL函数: 单行函数.多行函数 单行函数: 操作数据对象 接受参数返回一个结果 只对一行进行变换 每行返回一个结果 可以转换数据类型 ...
- MySQL丨删除一张表小常识
在MySQL里面 ,对于删除一张表里面的所有内容有两种语句: 1.delete from table_name; 2.truncate table table_name; 解析:以上两种方式都可以删除 ...