hdu 4277 USACO ORZ

1 篇文章 0 订阅

USACO ORZ

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


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
 

题意:某人需要用所有的栅栏围成一个三角形,计算最多可以围成多少种不同(至少一条边不同)的三角形?

分析:用set构造唯一值判重,注意要用到所有的木棒,构成三角形
#include <iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
set<long long>temp;
 int t,n,s[20],sum;
void dfs(int a,int b,int c,int num)
{
    if(num==n)
    {
        if(c>a||c>b||b>a) return;
        if(c&&b&&a&&c+b>a)
        {
            long long tmp=a*sum*sum+b*sum+c;
            temp.insert(tmp);
        }
        return;
    }
    dfs(a+s[num],b,c,num+1);
    dfs(a,b+s[num],c,num+1);
    dfs(a,b,c+s[num],num+1);
}
int main()
{
   scanf("%d",&t);
   while(t--)
   {
       sum=0;
       scanf("%d",&n);
       for(int i=0;i<n;i++)
        {
            scanf("%d",&s[i]);
            sum+=s[i];
        }
       if(n<3)
       {
           printf("0\n");continue;
       }
       temp.clear();
       dfs(0,0,0,0);
//       set<long long>::iterator it;
//       for(it=temp.begin();it!=temp.end();it++)
//        cout<<*it <<endl;
       printf("%d\n",temp.size());
   }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值