题目链接:Codeforces 437E The Child and Polygon

题目大意:给出一个多边形,问说有多少种切割方法。将多边形切割为多个三角形。

解题思路:首先要理解向量叉积的性质,一開始将给出的点转换成顺时针。然后用区间dp计算。dp[i][j]表示从点i到点j能够有dp[i][j]种分割方法。然后点i和点j能否够做为分割线。要经过推断。即在i和j中选择的话点k的话,点k要在i,j的逆时针方。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll; const int N = 205;
const ll MOD = 1e9+7; struct point {
ll x, y;
ll operator * (const point& c) const {
return x * c.y - y * c.x;
}
point operator - (const point& c) const {
point u;
u.x = x - c.x;
u.y = y - c.y;
return u;
}
}p[N];
int n;
ll dp[N][N]; void init () {
scanf("%d", &n);
memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++)
scanf("%lld %lld", &p[i].x, &p[i].y); ll tmp = 0;
p[n] = p[0];
for (int i = 0; i < n; i++)
tmp += p[i] * p[i+1]; if (tmp < 0)
reverse(p, p + n);
} ll solve (int l, int r) {
if (dp[l][r] != -1)
return dp[l][r]; ll& ans = dp[l][r];
ans = 0; if (r - l == 1)
return ans = 1; for (int i = l + 1; i < r; i++) {
if ((p[l] - p[r]) * (p[i] - p[r]) > 0)
ans = (ans + solve(l, i) * solve(i, r)) % MOD;
}
return ans;
} int main () {
init();
printf("%lld\n", solve(0, n-1));
return 0;
}

Codeforces 437E The Child and Polygon(间隔DP)的更多相关文章

  1. Codeforces 437E The Child and Polygon

    http://codeforces.com/problemset/problem/437/E 题意:求一个多边形划分成三角形的方案数 思路:区间dp,每次转移只从一个方向转移(L,R连线的某一侧),能 ...

  2. Codeforces 438E The Child and Binary Tree [DP,生成函数,NTT]

    洛谷 Codeforces 思路 看到计数和\(998244353\),可以感觉到这是一个DP+生成函数+NTT的题. 设\(s_i\)表示\(i\)是否在集合中,\(A\)为\(s\)的生成函数,即 ...

  3. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  4. Codeforces 437B The Child and Set

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

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

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

  6. POJ 3280 间隔DP

    字符串,每次插入或删除字符需要一定的价格,问:我怎样才能使这个字符串转换成字符串回文,花最少. 间隔DP 当DP到区间[i,j+1]时,我们能够在i-1的位置加入一个str[j+1]字符,或者将在j+ ...

  7. Codeforces 437A The Child and Homework

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

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

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

  9. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

随机推荐

  1. VMware Player安装centos

    用VMware Player安装centos 到物理硬盘 想要學Linux,但卻不知道如何弄成雙系統?那就使用用虛擬機器來安裝Linux.使用虛體機器來玩,好處除了好裝之外,也不怕把電腦搞壞,不論你怎 ...

  2. poj2387(最短路)

    题目连接:http://poj.org/problem?id=2387 题意:有N个点,给出从a点到b点的距离,当然a和b是互相可以抵达的,问从1到n的最短距离. 分析:最短路裸题. #include ...

  3. hdu4004(二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 大致题意 二分最大跳跃能力,判断是否可以在m次内到达对岸! 分析:由于求青蛙最小弹跳能力,所以二 ...

  4. Python的控制结构(转)

    首先我的工作第一语言是c/c++(面向对象子集).选择学习python一方面是因为看很多人都说python开发效率高,所以想验证一下:另一方面,Eric S. Raymond在文章:如何成为一名黑客 ...

  5. 用xml建立仓库的逻辑层的操作

    package com.repositoryclient.xml; import java.io.FileNotFoundException; import java.io.FileOutputStr ...

  6. 斯坦福ML公开课笔记14——主成分分析

    上一篇笔记中,介绍了因子分析模型,因子分析模型使用d维子空间的隐含变量z来拟合训练数据,所以实际上因子分析模型是一种数据降维的方法,它基于一个概率模型,使用EM算法来预计參数. 本篇主要介绍PCA(P ...

  7. poj 3172 Scales 搜索

    其实这个题目要是注意到了题目的一点关键性的描述就会变得很简单,题意是给出的砝码是至少是前两个的和的,有了这一点,那么砝码的数量应该就在几十左右,这样的话适当剪枝的搜索是应该可以过的. #include ...

  8. IOS程序设相关计开发技巧

    iOS programming architecture and design guidelines 原文地址:http://blog.mugunthkumar.com/articles/ios-pr ...

  9. Android 访问Android Wear数据层Api——同步Data Items

    Data Items它被用来同步手机和wear数据接口,一个Date Items通常包含以下几个部分: Payload 字节数组.无论你需要设置数据类型,我们同意对象序列化和反序列化,大小不能超过10 ...

  10. Class ThreadPoolExecutor

    Class ThreadPoolExecutor java.lang.Object java.util.concurrent.AbstractExecutorService java.util.con ...