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 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

Source

2012 ACM/ICPC Asia Regional Changchun Online

暴力搜索+set判重

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
set<long long> sset;
int t,n,aar[20];
void dfs(int a,int b,int c,int rt)
{
      if(rt==n)
      {
            if(a>b||b>c||a>c) return ;
            if(a&&b&&c&&(a+b)>c)
            {
                  long long temp=100000000*a+1000000*b+c;
                  sset.insert(temp);
            }
            return ;
      }
      dfs(a+aar[rt],b,c,rt+1);
      dfs(a,b+aar[rt],c,rt+1);
      dfs(a,b,c+aar[rt],rt+1);
}
int main()
{
      scanf("%d",&t);
      while(t--)
      {
            sset.clear();
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                  scanf("%d",&aar[i]);
            dfs(0,0,0,0);
            printf("%I64d\n",sset.size());
      }
      return 0;
}

  

时间: 2024-10-11 19:46:59

hdu 4277的相关文章

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

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

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 pastur

10道ACM例题让你三天学会STL

清明节给大一的孩子们讲了点STL的应用,下了些功夫,搬到这里来供大家学习交流. 1.泛型程序设计简介与迭代器的介绍 2.常见的STL容器及其例题应用(UVA10474,UVA101,UVA10815,UVA156,UVA540,UVA136 HDU1027,CF501B,HDU1716,HDU4277) 3.相关练习和思路 1.泛型程序设计简介与迭代器的介绍 1.1 泛型程序设计简介 泛型程序设计,简单地说就是使用模板的程序设计法.将一些常用的数据结构(比如链表,数组,二叉树)和算法(比如排序,

hdu 4274 Spy&amp;#39;s Work(水题)

Spy's Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1266    Accepted Submission(s): 388 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU 4280 Island Transport(网络流模板)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 Problem Description In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies

hdu 4274 Spy&#39;s Work(水题)

Spy's Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1266    Accepted Submission(s): 388 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;