codeforces 250 div2 E

E. The Child and Polygon
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This time our child has a simple polygon. He has to find the number of ways to split the polygon into non-degenerate triangles, each way must satisfy the following requirements:

  • each vertex of each triangle is one of the polygon vertex;
  • each side of the polygon must be the side of exactly one triangle;
  • the area of intersection of every two triangles equals to zero, and the sum of all areas of triangles equals to the area of the polygon;
  • each triangle must be completely inside the polygon;
  • each side of each triangle must contain exactly two vertices of the polygon.

The picture below depicts an example of a correct splitting.

Please, help the child. Calculate the described number of ways modulo 1000000007 (109  +  7) for him.

Input

The first line contains one integer n (3 ≤ n ≤ 200) — the number of vertices of the polygon. Then follow n lines, each line containing two integers. The i-th line contains xi, yi (|xi|, |yi| ≤ 107) — the i-th vertex of the polygon in clockwise or counterclockwise order.

It's guaranteed that the polygon is simple.

Output

Output the number of ways modulo 1000000007 (109  +  7).

Sample test(s)
input
4
0 0
0 1
1 1
1 0
output
2
input
4
0 0
1 0
0 1
-1 0
output
1
input
5
0 0
1 0
1 1
0 1
-2 -1
output
3
Note

In the first sample, there are two possible splittings:

In the second sample, there are only one possible splitting:



#include <bits/stdc++.h>

using namespace std;
#define LL long long
#define eps 1e-8
#define N 205
const int mod = 1e9 + 7 ;

int n;
LL d[N][N];

struct point
{
    LL x, y;
    LL operator * (const point &b) const
    {
        return x * b.y - y * b.x ;
    }
    point operator - (const point &b) const
    {
        return point {x - b.x, y - b.y} ;
    }
} p[N];

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%I64d%I64d", &p[i].x, &p[i].y);

    LL temp = 0;
    p[n] = p[0] ;
    for(int i = 0; i < n; i++)
        temp += p[i] * p[i + 1];
    if(temp < 0) reverse(p, p + n);

    //memset(d, -1, sizeof d);

    for(int i = 0; i < n; i++) d[i][i+1] = 1;

    for(int l = 2; l <= n; l++)
    for(int i = 0; i + l < n; i++)
    {
        int j = i + l;
        d[i][j] = 0 ;
        for(int k = i + 1; k < j; k++)
        {
            LL t = (p[i] - p[j]) * (p[k] - p[j]);
            if(t > 0)
            d[i][j] = (d[i][j] + (d[i][k] * d[k][j]) % mod) % mod ;
        }
        //printf("%d--%d  %d\n", i, j, d[i][j]);
    }

    printf("%I64d\n", d[0][n - 1]);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值