[Usaco2008 Oct][BZOJ1600] 建造栅栏

1600: [Usaco2008 Oct]建造栅栏

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 949  Solved: 557
[Submit][Status][Discuss]

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。三边之和大于第四边。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int f[3000][5];
int n;
int main()
{
    scanf("%d",&n);
    f[0][0]=1;
    int maxlength=(n+1)/2-1;
    for (int j=1;j<=4;j++)
        for (int i=1;i<=n;i++)
            for (int k=1;k<=min(maxlength,i);k++)
                f[i][j]+=f[i-k][j-1];
    printf("%d",f[n][4]);
    return 0;
}

 

posted @ 2015-07-17 17:01  ws_fqk  阅读(201)  评论(0编辑  收藏  举报