HDU 4277 USACO ORZ(DFS暴搜+set去重)
原题代号: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
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.
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)
number of different pastures.
# 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去重)的更多相关文章
- hdu 4277 USACO ORZ dfs+hash
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- hdu 4277 USACO ORZ DFS
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 4277 USACO ORZ(暴力+双向枚举)
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 4277 USACO ORZ (dfs暴搜+hash)
题目大意:有N个木棒,相互组合拼接,能组成多少种不同的三角形. 思路:假设c>=b>=a 然后枚举C,在C的dfs里嵌套枚举B的DFS. #include <iostream> ...
- hdu 4277 USACO ORZ(dfs+剪枝)
Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...
- hdu 4277 USACO ORZ (Dfs)
题意: 给你n个数,要你用光所有数字组成一个三角形,问能组成多少种不同的三角形 时间分析: 3^15左右 #include<stdio.h> #include<set> usi ...
- hdu 4277 USACO ORZ
没什么好方法,只能用dfs了. 代码如下: #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- HDU 4284 Travel (Folyd预处理+dfs暴搜)
题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...
- 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 ... ...
随机推荐
- DB.JDBC_jar_下载
1.Download Microsoft JDBC Driver for SQL Server - SQL Server _ Microsoft Docs.html(https://docs.micr ...
- 更新代码 出现 You need to upgrade the working copy first 错误
今天更新了Eclipse的subclipse插件,更新代码报如下错误: svn: The working copy at 'E:\591woospace\kst_fashion_alipay_v1.2 ...
- [转帖]Oracle 使用sqlnet.ora/trigger限制/允许某IP或IP段访问指定用户
Oracle 使用sqlnet.ora/trigger限制/允许某IP或IP段访问指定用户 原创 Oracle 作者:maohaiqing0304 时间:2016-05-03 17:05:46 17 ...
- Java 线程池 8 大拒绝策略,面试必问!
前言 谈到java的线程池最熟悉的莫过于ExecutorService接口了,jdk1.5新增的java.util.concurrent包下的这个api,大大的简化了多线程代码的开发.而不论你用Fix ...
- linux工具之screen
screen官方网址:http://www.gnu.org/software/screen/ 参考文章:http://man.linuxde.net/screen 简介 Screen是一款由GNU计划 ...
- 搜索专题: HDU1027Ignatius and the Princess II
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 高德地图搜索功能以及清除搜索结果maker
第一次写文章,写得不好各位看官见谅~ (pσ_σ)P首先这是一个vue里面的项目,高德地图api是直接CDN进来的,所以使用了global来调用,默认已经初始化了一个地图,为了实现一个输入框搜索功能和 ...
- 小a的轰炸游戏(差分,前缀和)
题目传送门 题意: 给出一个n*m的矩形,然后有两个操作. 1操作,对一个给出的菱形,对菱形范围内的东西进行+1. 2操作,对一个上半菱形的区域,进行+1操作. 最后求矩形内各个数的异或和. 思路: ...
- git flow 基础了解
git flow 软件开发中的一个分支管理流程.利用它可以让软件开发有条不紊的进行,先对它进行一个大概的了解吧,后面工作了实际用到了在深入研究一下. 先看下它的工作流程: 这张图看着一脸茫然,先放在这 ...
- Kali Linux安装及中文指南
Kali Linux安装及中文指南 Kali Linux安装教程:https://blog.csdn.net/u012318074/article/details/71601382 Kali Linu ...