题意:(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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. CF821 E. Okabe and El Psy Kongroo 矩阵快速幂

    LINK 题意:给出$n$条平行于x轴的线段,终点$k$坐标$(k <= 10^{18})$,现在可以在线段之间进行移动,但不能超出两条线段的y坐标所夹范围,问到达终点有几种方案. 思路:刚开始 ...

  7. 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)的做法,肯定行不通,然后我们考虑使用矩阵加速 \( ...

  8. 【codeforces 821E】Okabe and El Psy Kongroo

    [题目链接]:http://codeforces.com/problemset/problem/821/E [题意] 一开始位于(0,0)的位置; 然后你每次可以往右上,右,右下3走一步; (x+1, ...

  9. codeforces E. Okabe and El Psy Kongroo(dp+矩阵快速幂)

    题目链接:http://codeforces.com/contest/821/problem/E 题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y- ...

随机推荐

  1. flex TweenLite

    本贴已在 AS天地会转发,大家可以参考:http://bbs.actionscript3.cn/viewthread.php?tid=11090&pid=91142&page=1&am ...

  2. Java多线程系列 JUC线程池01 线程池框架

    转载  http://www.cnblogs.com/skywang12345/p/3509903.html 为什么引入Executor线程池框架 new Thread()的缺点 1. 每次new T ...

  3. MyCat:开源分布式数据库中间件

    mycat 的主要配置文件 schema.xml rule.xml server.xml 客户端连接mycat mysql -h192.168.1.1 -P8806 -uroot -pwangxiao ...

  4. 在eclipse中引入jquery.js文件报错的解决方案

    从官方下载的jquery.js在myeclipse始终用个大大的红叉,看着很不爽,如何解决呢:jquery.js在myeclipse中报错:jquery.js -> 鼠标右键 -> MyE ...

  5. java:练习超市卖场

    java:练习超市卖场 涉及到:大商品类,具体商品(以书为例),卖场类 Goods,Book,superMart,  商品类Goods: public interface Goods { //商品类 ...

  6. Android Studio Mac版快捷键

    mac上按键符号 ⌥ : option / alt ⇧ : shift ⌃ : control ⌘ : command ⎋ : esc (一)查找/查看相关 搜索任意内容 双击 sft 当前文件查找/ ...

  7. POJ 2240 Arbitrage(Floyed-Warshall算法)

    题意:给出n种货币,m种兑换比率(一种货币兑换为另一种货币的比率),判断测试用例中套汇是否可行.(套汇的意思就是在经过一系列的货币兑换之后,是否可以获利.例如:货币i→货币j→货币i,这样兑换后,是否 ...

  8. hadoop_学习_01_入门准备

    一.入门准备 1.零基础学习Hadoop 2.大数据初学者应该知道的知识

  9. PHP获取指定日期是星期几的实现方法

    这篇文章主要介绍了PHP获取指定日期是星期几的实现方法,涉及php针对日期的读取.判断与字符串.数组相关运算操作技巧,需要的朋友可以参考下 本文实例讲述了PHP获取指定日期是星期几的实现方法.分享给大 ...

  10. docker 安装过程