zoukankan      html  css  js  c++  java
  • BZOJ 1600: [Usaco2008 Oct]建造栅栏

    1600: [Usaco2008 Oct]建造栅栏

    Time Limit: 5 Sec  Memory Limit: 64 MB

    Description

    勤奋的Farmer John想要建造一个四面的栅栏来关住牛们。他有一块长为n(4<=n<=2500)的木板,他想把这块本板切成4块。这四块小木板可以是任何一个长度只要Farmer John能够把它们围成一个合理的四边形。他能够切出多少种不同的合理方案。注意: *只要大木板的切割点不同就当成是不同的方案(像全排列那样),不要担心另外的特殊情况,go ahead。 *栅栏的面积要大于0. *输出保证答案在longint范围内。 *整块木板都要用完。

    Input

    *第一行:一个数n

    Output

    *第一行:合理的方案总数

    Sample Input

    6

    Sample Output

    6


    输出详解:

    Farmer John能够切出所有的情况为: (1, 1, 1,3); (1, 1, 2, 2); (1, 1, 3, 1); (1, 2, 1, 2); (1, 2, 2, 1); (1, 3,1, 1);
    (2, 1, 1, 2); (2, 1, 2, 1); (2, 2, 1, 1); or (3, 1, 1, 1).
    下面四种 -- (1, 1, 1, 3), (1, 1, 3, 1), (1, 3, 1, 1), and (3,1, 1, 1) – 不能够组成一个四边形.

    HINT

     

    Source


    好的,这是一题DP递推。我一开始用了三位状态+n^3的递推,果断TLE了,我真是作死!实际上只要保证任意一条边小于总长度的一半就可以了,我偷了个懒,算了全部的结果,结果死的爽爽的!以后做题不能这么随意了。所以应该是二维的递推f[i][j]表示i块木板拼了j个长度的方案数,并时刻保证任意一条边小于总长度的一般就可以了。

    代码:

    /*Author:WNJXYK*/
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<set>
    using namespace std;
    
    #define LL long long
    
    inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
    inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
    inline int remin(int a,int b){if (a<b) return a;return b;}
    inline int remax(int a,int b){if (a>b) return a;return b;}
    inline LL remin(LL a,LL b){if (a<b) return a;return b;}
    inline LL remax(LL a,LL b){if (a>b) return a;return b;}
    
    int n,mx;
    int f[5][2505];
    int main()
    {
    	f[0][0]=1;
    	scanf("%d",&n);
    	int mx=(n+1)/2-1;
    	for(int i=1;i<=4;i++)
    	    for(int j=1;j<=n;j++)
    		    for(int k=1;k<=remin(mx,j);k++)
    			    f[i][j]+=f[i-1][j-k];
        printf("%d
    ",f[4][n]);
    	return 0;
    }
    



  • 相关阅读:
    基于ZooKeeper和Thrift构建动态RPC调用
    菜鸡的Java笔记 api 文档
    菜鸡的Java笔记 第二十四
    菜鸡的Java笔记 第二十三
    菜鸡的Java笔记 第二十二
    菜鸡的Java笔记 实践
    Python 函数 参数传递
    python 函数的定义及调用语法,map 方法,函数嵌套递归
    java关键字
    菜鸡的Java笔记 第二十一 final 关键字
  • 原文地址:https://www.cnblogs.com/WNJXYK/p/4063933.html
Copyright © 2011-2022 走看看