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 ... ...
随机推荐
- java 内部编译异常的处理方法
1.可能存在的问题. 在cmd 输入 java -version 和javac -version 检验java的环境是否正常,不正常就卸载重装. 搞定!
- 简述Vue项目中返回上一页
1.背景 由于Vue所生成的项目叫做单页应用,即SPA,如果还是使用jQuery中的go(-)或back()是行不通的,所以,我们使用到了Vue中的编程式导航. 2.基本使用 定义返回按钮: < ...
- [Web 前端] 024 js 的定时器及函数
1. Javascript 定时器 1.1 计时事件 设定一个间隔,时间到了后准时执行代码,此为"计时事件" 1.2 作用 1.制作动画 2.异步操作 1.3 定时器的类型及语法 ...
- 《剑指offer》面试题26 复杂链表的复制 Java版
(定义一个新的数据结构,每个节点除了具有普通链表的next域外,还有一个额外的引用指向任意节点.我们要对由该特殊数据结构形成的链表进行复制.) 我的方法:也就是克隆一个这种特殊链表,很快想到先不考虑原 ...
- P1177快速排序
这是一个快速排序的模板题.拿到题后便写了quicksort(确定一个基准数,利用两个哨兵,把大的放右边,小的放左边,再递归实现排序),但是竟然TLE了60pts(???),于是翻看dalao们的题解, ...
- Python 入门之 推导式
Python 入门之 推导式 推导式就是构建比较有规律的列表,生成器,字典等一种简便的方式 1.推导式 (1)列表推导式 : <1> 普通循环: [变量 for循环] print([i f ...
- php中引入facebook的messenger消息接口
前一段时间需要开发一个messenger的消息接口,但是facebook的官方文档似是而非,而且由于在国内比较小众,之前也没有另外的人写过中文的开发教程,只好自己进行了一番研究并完成了一个demo,希 ...
- React全家桶入门
http://blog.csdn.net/column/details/14545.html
- 410-基于XCVU9P+ C6678的40G光纤的加速卡
基于XCVU9P+ C6678的40G光纤的加速卡 一.板卡概述 二.处理板技术指标 • 板卡为自定义结构,板卡大小332mmx260mm; • FPGA采用Xilinx Virtex Ultra ...
- [易学易懂系列|golang语言|零基础|快速入门|(一)]
golang编程语言,是google推出的一门语言. 主要应用在系统编程和高性能服务器编程,有广大的市场前景,目前整个生态也越来越强大,未来可能在企业应用和人工智能等领域占有越来越重要的地位. 本文章 ...