• 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-----------------------------------------------------------------------
  • 相关阅读:
    xxl-job docker版分布式任务
    nginx学习http_access_module模块
    nginx学习sub_filter模块
    nginx学习首页随机模块
    mysql使用命令
    laravel数据填充
    LINUX下统计代码行数
    检查字符串结尾 判断一个字符串(str)是否以指定的字符串(target)结尾。
    右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组。
    确保字符串的每个单词首字母都大写,其余部分小写。
  • 原文地址:https://www.cnblogs.com/fenice/p/5937851.html
Copyright © 2020-2023  润新知