[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- ...
随机推荐
- LeetCode:寻找重复数【287】
LeetCode:寻找重复数[287] 题目描述 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个重复的整数.假设只有一个重复的整数 ...
- Data Structure Binary Tree: Populate Inorder Successor for all nodes
http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ #include <iostream> #in ...
- leetcode 901. Online Stock Span
Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of ...
- P3214 [HNOI2011]卡农
题目 P3214 [HNOI2011]卡农 在被一题容斥\(dp\)完虐之后,打算做一做集合容斥这类的题了 第一次深感HNOI的毒瘤(题做得太少了!!) 做法 求\([1,n]\)组成的集合中选\(m ...
- thinkphp 的 Action 控制器中的系统常量总结
THINK_PATH // ThinkPHP系统目录 APP_PATH // 当前项目目录 APP_NAME // 当前项目名称 CONTROLLER_NAME // 当前控制器名称 MODULE_N ...
- 适用grunt的注意点
0.使用grunt可以为前端开发省去很多工作量,与git版本控制器配合起来不要太完美,一般也都是这么用的: 1.先安装node.js,下载软件安装就行了,一般自带npm管理器; 2.通过npm安装gr ...
- 算法(Algorithms)第4版 练习 1.3.37
package com.qiusongde.creative; import com.qiusongde.Queue; import edu.princeton.cs.algs4.StdOut; pu ...
- spring boot拦截器
实现自定义拦截器只需要3步: 1.创建我们自己的拦截器类并实现 HandlerInterceptor 接口. 2.创建一个Java类继承WebMvcConfigurerAdapter,并重写 addI ...
- mybatis学习(四)
创建mybatis工程 工程目录: 具体步骤: 1.创建sqlMapConfig.xml文件,配置mybatis的运行环境,事物,数据源,加载mapper映射文件等. 2.创建po类(查询或者返回的属 ...
- 大数据日志分析产品——SaaS Cloud, e.g. Papertrail, Loggly, Sumo Logic;Open Source Frameworks, e.g. ELK stack, Graylog;Enterprise Products, e.g. TIBCO LogLogic, IBM QRadar, Splunk
Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brough ...