E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to k…
LINK 题意:给出$n$条平行于x轴的线段,终点$k$坐标$(k <= 10^{18})$,现在可以在线段之间进行移动,但不能超出两条线段的y坐标所夹范围,问到达终点有几种方案. 思路:刚开始以为限制只是到达线段上就必须沿线段走,后来才发现是要求走y坐标所夹范围,那么就简单多了,很容易看出是个递推形DP,然而数据量有点大,k为10的18次,一般转移显然不可行.由于是个递推,而且y坐标最大也只有15,故使用矩阵优化递推复杂度即可. /** @Date : 2017-07-04 16:06:18…
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to k…
题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y-1)或者(x+1,y)或者(x+1,y+1)三个位子之一.现在一共有N段线段,每条线段都是平行于X轴的.我们如果此时x是在这段线段之内的话,我们此时走到的点(x,y)需要满足0<=y<=Ci.现在保证一段线段的终点,一定是下一段线段的起点.问我们从起点走到终点的行走方案数. dp方程比较显然:dp[i][j]+=dp[i-1][j]+dp[-1][j-1]+dp[i-1][j+1] 之后构造一…
题目链接:http://codeforces.com/contest/821/problem/E 题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y-1)或者(x+1,y)或者(x+1,y+1)三个位子之一. 现在一共有N段线段,每条线段都是平行于X轴的.我们如果此时x是在这段线段之内的话,我们此时走到的点(x,y)需要满足0<=y<=Ci. 现在保证一段线段的终点,一定是下一段线段的起点.问我们从起点走到终点的行走方案数. 题解:简单的dp+…
E. Okabe and El Psy Kongroo     Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points…
E. Okabe and El Psy Kongroo   Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (…
首先我们从最简单的dp开始 \(dp[i][j]=dp[i-1][j]+dp[i-1][j+1]+dp[i-1][j-1]\) 然后这是一个O(NM)的做法,肯定行不通,然后我们考虑使用矩阵加速 \(\begin{bmatrix} 1\\ 0 \\0\\0\end{bmatrix}\quad\) 鉴于纵坐标很小,考虑全部记录下来.写成一个向量的形式.如上, 第i行的数表示纵坐标为i-1的方案数. 然后我们考虑转移 \(\begin{bmatrix} 1&1&0&0\\1&1…
题意:(0,0)走到(k,0),每一部分有一条线段作为上界,求方案数. 解题关键:dp+矩阵快速幂,盗个图,注意ll 关于那条语句为什么不加也可以,因为我的矩阵C,就是因为多传了了len的原因,其他位置都是0,所以不需要加 #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<iostream>…
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h> using namespace std; typedef __int64 LL; struct data { LL mat[][]; }; LL mod = 1e9 + ; data operator *(data a , data b) { data res; ; i <= ; ++i) { ;…