[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- ...
随机推荐
- MyBatis:学习笔记(4)——动态SQL
MyBatis:学习笔记(4)——动态SQL 如果使用JDBC或者其他框架,很多时候需要你根据需求手动拼装SQL语句,这是一件非常麻烦的事情.MyBatis提供了对SQL语句动态的组装能力,而且他只有 ...
- HDU - 1175 连连看 【DFS】【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1175 思路 这种题一想到就用搜索, 但是内存是32m 用 bfs 会不会MLE 没错 第一次 BFS的 ...
- 每天一个Linux命令(2)cd命令
cd命令用来切换工作目录至dirname. 其中dirName表示法可为绝对路径或相对路径.若目录名称省略,则变换至使用者的home directory(也就是刚login时所在的目录).另外,~也表 ...
- Eclipse快捷键与Notepad++ 快捷建冲突的问题
notepad++添加了zen coding插件以后,notepad++默认的快捷键中Alt+/也是其快捷键中的一个,表示toggle comment,而用myeclipce或eclipse的朋友都知 ...
- HBase启动后端口60010无法访问
配置好HBase后,想从浏览器通过端口60010看下节点情况,但是提示无法访问 在服务器上netstat -natl|grep 60010 发现并没有60010端口 原来是因为HBase 1.0 之后 ...
- Hive- 大数据仓库Hive
什么是 Hive? Hive 是由 FaceBook 开源用于解决少量数据结构化日志的数据统计.Hive是基于 Hadoop 的一个数据仓库工具,可以将结构化的数据文件映射成一张表,并提供类SQL查询 ...
- js文件报错Syntax error on token "Invalid Regular Expression Options", no accurate correction
Syntax error on token "Invalid Regular Expression Options", no accurate correction 1.选中报错的 ...
- MySQL常用方法
1.INSTR,例:INSTR(content,'\"SHOP_DES\"')>0,返回字符串在某一个字段的内容中第一次出现位置,没有为0 2.REPLACE,例:conte ...
- Android: 一个两点触控的案例
下面是一个两点触控的案例代码: package com.zzj; import android.app.Activity; import android.os.Bundle; import andro ...
- 【遍历二叉树】11把二叉树转换成前序遍历的链表【Flatten Binary Tree to Linked List】
本质上是二叉树的root->right->left遍历. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...