$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. [LOJ2065] [SDOI2016]模式字符串

    题目链接 洛谷:https://www.luogu.org/problemnew/show/P4075 LOJ:https://loj.ac/problem/2065 Solution 这种题看起来就 ...

  2. JDK8-lambda表达式以及接口可以定义默认方法

    一.Lambda表达式 1.Lamdba Lambda 允许把函数作为一个方法的参数,使用Lamdba可以让开发的代码更加简洁,但是易读性差,新人不了解Lamdba表达式或者代码功底有点差,不容易读懂 ...

  3. This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.

    记事本打开csproj文件 搜索nuget 删除Target节点 类似如下: <Target Name="EnsureBclBuildImported" BeforeTarg ...

  4. Python定义点击右上角关闭按钮事件

    Python定义点击右上角关闭按钮事件(Python defines the event of clicking the close button in the upper right corner) ...

  5. javascript中的prototype和__proto__的理解

    在工作中有时候会看到prototype和__proto__这两个属性,对这两个属性我一直比较蒙圈,但是我通过查阅相关资料,决定做一下总结加深自己的理解,写得不对的地方还请各位大神指出. 跟__prot ...

  6. centos7开启80端口及其他端口

    首先centos7的防火墙由iptables改为了firewalld 1. 执行命令:firewall-cmd --zone=public --add-port=80/tcp  --permanent ...

  7. Charles中文破解版下载安装及使用教程(附带免费下载链接)

    一. 简介及安装 Charles 是在 PC 端常用的网络封包截取工具,但它不仅仅能在pc端使用,还可以在手机ios和安卓端都可以使用.我们在做移动开发或者测试网页app时候,为了调试与服务器端的网络 ...

  8. 聊Java中的任务调度的实现方法及比较

    前言 任务调度是指基于给定时间点,给定时间间隔或者给定执行次数自动执行任务.本文由浅入深介绍四种任务调度的 Java 实现: Timer ScheduledExecutor 开源工具包 Quartz ...

  9. php error_log记录日志的使用方法--拿来即用,超简单

    如果本文对你有用,请爱心点个赞,提高排名,帮助更多的人.谢谢大家!❤ 如果解决不了,可以在文末进群交流. 如果对你有帮助的话麻烦点个[推荐]~最好还可以follow一下我的GitHub~感谢观看! 对 ...

  10. 【hadoop】在eclipse上运行WordCount的操作过程

    序:本以为今天花点时间将WordCount例子完全理解到,但高估自己了,更别说我只是在大学选修一学期的java,之后再也没碰过java语言了 总的来说,从宏观上能理解具体的程序思路,但具体到每个代码有 ...