题目链接: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;
}
分享到:
相关推荐
题目分析:最优性问题,且是对区间操作的,而且数据范围满足 n^3 的时间复杂度,综上可以考虑区间dp,因为题目已经明确了需要求什么,所以我们不妨设 dp[ i ][ j ] 为区间 [ i , j ] 合并后的最短数列的长度,因为...
E. Array Shrinking time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a1,a2,…,an. You can perform the following operation...
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
codeforces每日一练。 题意: 给一棵树,每个点有一个点权,每条边有一个边权,求一条链使得点权和-边权和最大。 思路: 由于我没看清楚题意,以为是求联通子图的点权和-边权和最大,用link-cut-tree写换根,wa10了两...
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
考虑用dp[x]dp[x]dp[x]记录前缀和为xxx的区间右端点。 那么这道题其实可以看成用map记录前缀和的路径,依次计算每个元素作为区间右端点并且满足条件时对答案的贡献,再进行累加即可。 iii是以a[i]a[i]a[i]为右端点的...
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Some of the Codeforces problems codes
题目大意:给出一个由 n 个点组成的树,现在可以询问 n/2 次(向下取整)LCA,确定根节点是哪个节点 题目分析:因为最多只能求 n/2 次lca,每次需要两个节点作为参数,也就是说每个点我们至多遍历一遍,读完题后没什么...
题意: 给出 nnn 个点,n−1n-1n−1 条边,最多询问 n2\frac{n}{2}2n 次,每次询问 u,vu,vu,v,会给出 uvuvuv的最近公共祖先,求树的根。 ...操作就是一个删除叶子节点的过程。 AC代码: const int N = 1010;...
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 185A - Plant 全测试点49个
codeforces每日一题。 题意: 给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。 思路: 针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2...
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
题目大意:给出 n 个数字组成的序列,现在可以对数列进行多次操作,每次操作可以选择其中一段连续的数列,用其平均数替换原位置,换句话说,若原连续数列为 1 2 3,则可以替换为 2 2 2,问如何操作可以使得最后答案...
Codeforces round 678 D2_Codeforces_源码