$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的更多相关文章

  1. [HDU 5293]Tree chain problem(树形dp+树链剖分)

    [HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...

  2. [LightOJ1004]Monkey Banana Problem(dp)

    题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

  5. 【UVA 1380】 A Scheduling Problem (树形DP)

    A Scheduling Problem   Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...

  6. BZOJ 2302: [HAOI2011]Problem c( dp )

    dp(i, j)表示从i~N中为j个人选定的方案数, 状态转移就考虑选多少人为i编号, 然后从i+1的方案数算过来就可以了. 时间复杂度O(TN^2) ------------------------ ...

  7. BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )

    概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...

  8. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  9. hiho1259 A Math Problem (数位dp)

    题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...

  10. BZOJ 2302: [HAOI2011]Problem c [DP 组合计数]

    2302: [HAOI2011]Problem c Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 648  Solved: 355[Submit][S ...

随机推荐

  1. JavaNetty

    Netty的简单使用: import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; import io.netty.ch ...

  2. top 命令 详解

    VIRT:virtual memory usage 虚拟内存 1.进程“需要的”虚拟内存大小,包括进程使用的库.代码.数据等 2.假如进程申请100m的内存,但实际只使用了10m,那么它会增长100m ...

  3. Node学习之(第三章:仿Apache显示目录列表的功能)

    前言 今天咱们用Node.js中的核心模块以及上节学习的模板引擎art-template来实现服务器软件Apache的大体功能.用过Apache的朋友都知道,我们只需把本地文件放置在Apache的ww ...

  4. TR-银行通信相关文档

    DMEE配置指南: https://wenku.baidu.com/view/06790649767f5acfa1c7cd73.html F110 DMEE配置: https://wenku.baid ...

  5. centOS学习part7:Oracle开机自启配置

    0 上一章(http://www.cnblogs.com/souvenir/p/3884904.html)我们用了很多时间以及很长的篇幅来介绍oracle的整个安装过程,希望对大家用所帮助.oracl ...

  6. 修改redhat7默认显示语言从中文为英文

    [delmore@localhost Desktop]$ su                               //切换到最高权限 Password:                    ...

  7. 服务网关ZuulFilter过滤器--pre/post/error的用法(校验请求信息,获取路由后的请求/响应信息,处理服务网关异常)

    微服务中Zuul服务网关一共定义了四种类型的过滤器: pre:在请求被路由(转发)之前调用 route:在路由(请求)转发时被调用 error:服务网关发生异常时被调用 post:在路由(转发)请求后 ...

  8. jenkens docker启动

    docker run \ -u root \ --rm \ -d \ -p 8080:8080 \ -p 50000:50000 \ -v jenkins-data:/var/jenkins_home ...

  9. centos7安装后,一些小优化

    1.设置静态ip vim /etc/sysconfig/network-scripts/ifcfg-ens33 将BOOTPROTO=dhcp修改为BOOTPROTO=static ONBOOT=no ...

  10. Kali下进行局域网断网攻击

    今天我就来演示一下在kali下的局域网断网攻击,即ARP地址欺骗,下图所要用到的arp地址欺骗状态图: 则: 第一步:假设主机A访问某网站,那么要告知某网站我的IP和MAC地址,但这是以广播的方式告知 ...