Problem 4 dp
$des$
小 $Y$ 十分喜爱光学相关的问题, 一天他正在研究折射.
他在平面上放置了 $n$ 个折射装置, 希望利用这些装置画出美丽的折线.
折线将从某个装置出发, 并且在经过一处装置时可以转向, 若经过的装置坐
标依次为 $(x_1, y_1), (x_2, y_2) ... (x_k, y_k ),$ 则必须满足:
$\bullet \forall j \in (1, k], y_j < y_{j - 1}$
$\bullet \forall j \in (2, k], x_{j - 2} < x_{j} < x_{j - 1} 或者 x_{j - 1} < x_j < x_{j - 2}$
求不同种的画法

$sol$
按 $x$ 坐标排序,$f_{i, 0/1}$ 表示以第 $i$ 个点为顶端下来向左或向右的折线的方案数
从左到右加点,考虑前 $i$ 个点构成的包含 $i$ 点的折线,由于新点横坐标最大, 所以只可能在折线的
第一位或第二位:
1. $\forall y_j < y_i, f_{i, 0} \gets f_{j, 1}$
2. $\forall y_j > y_i, f_{j, 1} \gets f_{k, 0} | x_k > x_j 且 y_k < y_i$
第二种情况可以前缀和优化, 复杂度 $O(n^2)$
$code$
#include <bits/stdc++.h> using std::pair; typedef long long ll;
typedef pair<int, int> pii; #define fst first
#define snd second const int oo = 0x3f3f3f3f; #define gc getchar()
inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} const int N = ;
const int mo = 1e9 + ; pii p[N + ];
int dp[N + ][], n; int main() {
n = read();
for(int i = ; i <= n; i++) p[i].fst = read(), p[i].snd = read();
sort(p + , p + n + );
for(int i = ; i <= n; i++) {
dp[i][] = dp[i][] = ;
for(int j = i - ; j >= ; j--)
if(p[j].snd > p[i].snd) (dp[j][] += dp[i][]) %= mo;
else (dp[i][] += dp[j][]) %= mo;
}
int ans = mo - n;
for(int i = ; i <= n; i++) ans = ((ans + dp[i][]) % mo + dp[i][]) % mo;
std:: cout << ans;
return ;
}
Problem 4 dp的更多相关文章
- [HDU 5293]Tree chain problem(树形dp+树链剖分)
[HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...
- [LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- 【UVA 1380】 A Scheduling Problem (树形DP)
A Scheduling Problem Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...
- BZOJ 2302: [HAOI2011]Problem c( dp )
dp(i, j)表示从i~N中为j个人选定的方案数, 状态转移就考虑选多少人为i编号, 然后从i+1的方案数算过来就可以了. 时间复杂度O(TN^2) ------------------------ ...
- BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )
概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- hiho1259 A Math Problem (数位dp)
题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...
- BZOJ 2302: [HAOI2011]Problem c [DP 组合计数]
2302: [HAOI2011]Problem c Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 648 Solved: 355[Submit][S ...
随机推荐
- PXC增量恢复添加节点(IST)
绕开SST通过IST方式添加Node到Percona XtraDB Cluster Gcache存储了所有的 writeset ,因此说这个集合的大小直接决定了允许其他节点宕机后多长时间内可以进行 ...
- 7、注解@Mapper、@MapperScan
7.注解@Mapper.@MapperScan 2018年09月20日 11:12:41 飞奔的加瓦 阅读数 3284 版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载. https ...
- 未检测到.NET CORE SDK 或者 新建项目没有.NET CORE 3.0选择项
终于解决了 首先先看自己的VS2019版本 由于楼主下载的 .NET CORE SDK 3.0.100-preview8-013656 焕然大悟 原来是版本不符合,需要用vs 2019 preview ...
- VBA 打印及破密
Sub 打印()ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=TrueCall dyEnd SubSub dy()Dim a%, b ...
- PHP利用preg_split函数格式化日期
// 2018/2/13 00:26:00.000 function format_date($date, $format='Y-m-d H:i:s') { if(empty($date)) retu ...
- 动画处理<并行和串行>
并行动画 当多个动画定义同时指向某个组件,并使用动画控制器启动时,就产生了并行动画(Parallel Animation).例如我们可以让一个组件: 移动的同时改变大小 旋转的同时边界颜色闪烁 圆形图 ...
- dicker第三章--网络管理
- 【面试突击】- SpringMVC那些事(一)
1.什么是Spring MVC ?简单介绍下你对springMVC的理解? Spring MVC是一个基于MVC架构的用来简化web应用程序开发的应用开发框架,它是Spring的一个模块,无需中间整合 ...
- Vue使用QRCode.js生成二维码
1.安装qrcode npm install qrcode 2.组件中引入qrcode import QRCode from 'qrcode' 3.html代码 <div><span ...
- Node.js学习之(第三章:简易小demo)
前言 我们前面已经学习完了Node中一些核心模块还有如何正确配置响应头的Content-Type,今天我们来实现一个简单的demo,巩固下之前学习的内容. 需求 我们平时访问百度或者其他大的门户网站的 ...