http://codeforces.com/problemset/problem/437/E

题意:求一个多边形划分成三角形的方案数

思路:区间dp,每次转移只从一个方向转移(L,R连线的某一侧),能保证正确。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
const ll Mod=;
ll f[][];
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[];
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll solve(int l,int r){
if (f[l][r]!=-) return f[l][r];
if (l>r) return f[l][r]=;
if (l+==r) return f[l][r]=;
f[l][r]=;
for (int i=l+;i<r;i++){
if ((p[r]-p[l])*(p[i]-p[l])<)
(f[l][r]+=(solve(l,i)*solve(i,r))%Mod)%=Mod;
}
return f[l][r];
}
int main(){
int n=read();
for (int i=;i<=n;i++) p[i].x=read(),p[i].y=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
f[i][j]=-;
double res=;
p[n+]=p[];
for (int i=;i<=n;i++)
res+=p[i]*p[i+];
if (res<){
for (int i=;i<=n/;i++) std::swap(p[i],p[n-i+]);
}
printf("%lld\n",solve(,n));
}

Codeforces 437E The Child and Polygon的更多相关文章

  1. Codeforces 437E The Child and Polygon(间隔DP)

    题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...

  2. Codeforces 437B The Child and Set

    题目链接:Codeforces 437B The Child and Set 開始是想到了这样的情况,比方lowbit之后从大到小排序后有这么几个数,200.100,60.50.S = 210.那先选 ...

  3. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  4. Codeforces 437A The Child and Homework

    题目链接:Codeforces 437A The Child and Homework 少看了一个条件,最后被HACK掉到203名,要不然就冲到100多一点了==.. 做这个题收获最大的是英语,A t ...

  5. Codeforces 437D The Child and Zoo(贪心+并查集)

    题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...

  6. Codeforces 437D The Child and Zoo(并查集)

    Codeforces 437D The Child and Zoo 题目大意: 有一张连通图,每个点有对应的值.定义从p点走向q点的其中一条路径的花费为途径点的最小值.定义f(p,q)为从点p走向点q ...

  7. Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树

    Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The ...

  8. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  9. 【codeforces 755D】PolandBall and Polygon

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. java日期int和String互转

    /** * 时间unix转换 * @param timestampString * @return */ public static String TimeStampDate(String times ...

  2. Java---设计模块(工厂方法)

    ★ 场景和问题 Java程序开发讲究面向接口编程,隐藏具体的实现类,可是如何得到接口呢? 工厂类的命名规范:***Factory 单例工厂方法的命名规范:getInstance() 工厂的本质是&qu ...

  3. 简要介绍EF(实体框架)

    原文地址:http://wenku.baidu.com/link?url=eutYH1QWA9y7fnxsxT9pZfJTPfa36nCI4R3Ub8Y4ybAVSgmXzEnXHwUj-GPFinn ...

  4. openstack手动部署简单记录

    1,关于网络规划部分,之前写的都好好的了,浏览器TM的崩溃了,我写几天的笔记 记录全给我丢了,我TM的多心疼啊! 大致说了关于openstack手动安装关于网络规划的问题 第一种legacy netw ...

  5. redis 网络流程图 <一>

    本来一直想好好读下redis源码.可是每次读了一点就不读了.  主要是没坚持每天都读. 隔几天看.就忘记前面的流程.就越来越不想看了.  很是蛋疼.这个还是要坚持读完的.打算这段时间都源码的时候.都大 ...

  6. build/core/base_rules.mk:195: already define

    编译错误: build/core/base_rules.mk:195: *** packages/apps/ScanDemo: MODULE.TARGET.APPS.ScanDemo already ...

  7. linux 切换用户之后变成-bash-x.x$的解决方法

    我们平时在linux下切换用户后命令行为什么会变成-bash-3.2$呢,我们来分析一下,这就是跟linux的机制有关联了,因为在linux下每次通过useradd创建新的用户时,都会将所有的配置文件 ...

  8. 微软在线测试题String reorder

    问题描述: Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 256MB DescriptionFor this question, yo ...

  9. 添加链接服务器 SQL SERVER

    使用sql语句: exec sp_addlinkedserver @server='serverontest',@provider='sqloledb',@srvproduct='',@datasrc ...

  10. Laravel资料

    http://laravel-cn.com/http://www.golaravel.com/docs/4.1/quick/https://github.com/search?q=Laravel&am ...