原题代号:HDU 4277

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4277

原题描述:

USACO ORZ

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

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个数,要你用光所有数字来构成一个三角形,问:能组成多少种不同的三角形;
题目思路:DFS深搜一遍,进行不必要的剪枝,然后使用set容器输入,去掉重复的值,最后输出set容器中值的个数。
AC代码:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; set<LL>s;
int num[];
int sum;
int n; void dfs(int a,int b,int c,int i)
{
if(i==n+)
{
if(a<=b&&b<=c)//重要部分保证a<=b<=c
if(a&&b&&c&&a+b>c)
s.insert(a*sum*sum+b*sum+c);//构造一个唯一值避免重复数值出现
return;
}
dfs(a+num[i],b,c,i+);
dfs(a,b+num[i],c,i+);
dfs(a,b,c+num[i],i+);
} int main()
{
//freopen("in.txt", "r", stdin);
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=; i<=n; i++)
{
cin>>num[i];
sum+=num[i];
}
s.clear();
dfs(,,,);
cout<<s.size()<<endl;
}
return ;
}

  

HDU 4277 USACO ORZ(DFS暴搜+set去重)的更多相关文章

  1. hdu 4277 USACO ORZ dfs+hash

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  2. hdu 4277 USACO ORZ DFS

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

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

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. hdu 4277 USACO ORZ (dfs暴搜+hash)

    题目大意:有N个木棒,相互组合拼接,能组成多少种不同的三角形. 思路:假设c>=b>=a 然后枚举C,在C的dfs里嵌套枚举B的DFS. #include <iostream> ...

  5. hdu 4277 USACO ORZ(dfs+剪枝)

    Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...

  6. hdu 4277 USACO ORZ (Dfs)

    题意: 给你n个数,要你用光所有数字组成一个三角形,问能组成多少种不同的三角形 时间分析: 3^15左右 #include<stdio.h> #include<set> usi ...

  7. hdu 4277 USACO ORZ

    没什么好方法,只能用dfs了. 代码如下: #include<iostream> #include<cstring> #include<cstdio> #inclu ...

  8. HDU 4284 Travel (Folyd预处理+dfs暴搜)

    题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...

  9. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

随机推荐

  1. 应用安全 - 工具 - 知道创宇 - CEYE检测平台

    DNS Query

  2. linux ftp使用相关

    ftp 7.7.6.201 21121 name:aaa password:123456

  3. [转帖]Oracle dba_objects和all_objects 最大的区别

    Oracle dba_objects和all_objects 最大的区别 原创 Oracle 作者:maohaiqing0304 时间:2015-08-14 15:07:18  9281  0   链 ...

  4. FTP-学习笔记(1)

    1.简单的SFTP.FTP文件上传下载 SftpTools.java package com.lfy.mian; import com.jcraft.jsch.*; import java.io.Fi ...

  5. gRPC go安装教程

    安装protobuf go get -u github.com/golang/protobuf/proto go get -u github.com/golang/protobuf/protoc-ge ...

  6. Pycharm2019.1.3破解

    搬运: T3ACKYHDVF-eyJsaWNlbnNlSWQiOiJUM0FDS1lIRFZGIiwibGljZW5zZWVOYW1lIjoi5bCP6bifIOeoi+W6j+WRmCIsImFzc ...

  7. 动态规划(股票交易)---只能进行 k 次的股票交易

    只能进行 k 次的股票交易 188. Best Time to Buy and Sell Stock IV (Hard) 题目描述:   只能进行K次股票交易,求能获得的最大利润 思路分析:   和只 ...

  8. vue梳理(2)

    -app.vue作为根组件被挂载到index.html文件里,其他的所有组件都是在app.vue组件里做文章. 展示给用户的就是app.vue里的内容,你觉得删的没有内容了但实际还有很多是因为什么呢? ...

  9. JavaScript回顾

    JavaScript是Web编程语言. JavaScript是一种基于对象的脚本语言 它是解释执行的 在客户端的浏览器中运行 可以被嵌入HTML文件中 代码以纯文本的形式存储在文件中 可以使用任何一种 ...

  10. 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器

    上篇文章是基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案,有兴趣的朋友可以查看. Nginx及nginx-rtmp-module安装 新建目录 mkdir /usr/loc ...