hdu 4277 USACO ORZ DFS

USACO ORZ

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3581    Accepted Submission(s): 1196

Problem Description

Like
everyone, cows enjoy variety. Their current fancy is new shapes for
pastures. The old rectangular shapes are out of favor; new geometries
are the favorite.
I. M. Hei, the lead cow pasture architect, is in
charge of creating a triangular pasture surrounded by nice white fence
rails. She is supplied with N fence segments and must arrange them into a
triangular pasture. Ms. Hei must use all the rails to create three
sides of non-zero length. Calculating the number of different kinds of
pastures, she can build that enclosed with all fence segments.
Two
pastures look different if at least one side of both pastures has
different lengths, and each pasture should not be degeneration.

Input

The first line is an integer T(T<=15) indicating the number of test cases.
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)

Output

For each test case, output one integer indicating the number of different pastures.

Sample Input

1
3
2 3 4

Sample Output

1

题意

给你n个棍子,棍子可以接起来,然后问你能够拼成多少个完全不同的三角形

题解

3^15=14 348 907,所以直接暴力然后hash一下就好

代码

int aa[maxn];
set<int> kiss;
int n;
void dfs(int a,int b,int c,int d)
{
    if(d==n)
    {
        if(a*b*c*d==0)
            return;
        if(a+b>c&&a<=b&&b<=c)
        {
            kiss.insert(a*1000010000+b*10000+c);
        }
        return;
    }
    dfs(a+aa[d],b,c,d+1);
    dfs(a,b+aa[d],c,d+1);
    dfs(a,b,c+aa[d],d+1);
}
int main()
{
    int t;
    RD(t);
    while(t--)
    {
        kiss.clear();
        RD(n);
        REP(i,n)
        {
            RD(aa[i]);
        }
        dfs(0,0,0,0);
        cout<<kiss.size()<<endl;
    }
}
时间: 2024-10-24 14:13:09

hdu 4277 USACO ORZ DFS的相关文章

HDU 4277 USACO ORZ(暴力+双向枚举)

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3809    Accepted Submission(s): 1264 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastu

hdu 4277 USACO ORZ(dfs+剪枝)

Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.I. M. Hei, the lead cow pasture architect, is in charge of creating a

HDU4277 USACO ORZ(dfs+set)

Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.I. M. Hei, the lead cow pasture architect, is in charge of creating a

hdu 4277

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3439    Accepted Submission(s): 1164 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastur

hdu 1501 Zipper (dfs+记忆化搜索)

Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6491    Accepted Submission(s): 2341 Problem Description Given three strings, you are to determine whether the third string can be formed

USACO zerosum DFS 1A

USER: Kevin Samuel [kevin_s1] TASK: zerosum LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.003 secs, 3508 KB] Test 2: TEST OK [0.003 secs, 3508 KB] Test 3: TEST OK [0.005 secs, 3508 KB] Test 4: TEST OK [0.000 secs, 3508 KB] Test 5

USACO concom DFS

写哭了,本来感觉是floyd,但是发现floyd根本不能连续地传递,然后看了题解写了个搜索,这个搜索我都没有想到= = 先贴个floyd的代码,先试图用DFS处理连续控股的情况,再用几个循环处理k1+k2+k3+...Kn 在第八组数据跪了 /* ID:kevin_s1 PROG:concom LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring&

hdu 1518 Square (dfs搜索可参考poj1011)

Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8589    Accepted Submission(s): 2784 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end

hdu 4277 2012长春赛区网络赛 dfs+hashmap ***

hashmap判重大法好 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0