POJ 3597 Polygon Division 多边形剖分

题目链接:

http://poj.org/problem?id=3597

Polygon Division

Time Limit: 2000MS
Memory Limit: 131072K
#### 问题描述 > Given a regular polygon, there are numerous ways to divide it into several triangles and/or quadrangles by adding some diagonals that do not properly intersect each other. For example, Figure 4 shows all ten different divisions of a regular pentagon into triangles and quadrangles. > > Figure 4: Divisions of a regular pentagon into triangles and quadrangles > > Given n, the number of sides of the polygon, compute the number of such divisions. #### 输入 > The input contains multiple test cases. Each test case consists of a single integer n (3 ≤ n ≤ 5000) on a separate line. The input ends where EOF is met. #### 输出 > For each test case, print the answer modulo 264 on a separate line. ####样例输入 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10

样例输出

1
3
10
38
154
654
2871
12925

题意

把正凸多边形剖成四边形和三角形的所有方案。

题解

[port]

代码

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
typedef unsigned long long ULL;

const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);

//start----------------------------------------------------------------------

const int maxn=5555;

ULL f[maxn],g[maxn];

void pre(){
    clr(g,0),clr(f,0);
    g[1]=g[2]=f[1]=f[2]=1;
    for(int i=3;i<maxn;i++){
        g[i]=0;
        for(int j=2;j<i;j++) g[i]+=f[j]*f[i-j+1];
        f[i]=g[i];
        for(int j=2;j<=i-2;j++) f[i]+=f[j]*g[i-j+1];
    }
}

int main() {
    pre();
    int tc,kase=0;
    int n;

    while(scf("%d",&n)==1){
        if(n<3) puts("0");
        prf("%llu
",f[n]);
    }
    return 0;
}

//end-----------------------------------------------------------------------
原文地址:https://www.cnblogs.com/fenice/p/5937851.html