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 ... ...
随机推荐
- diff patch比较文件打补丁
比较文件将结果保存到patch文件:diff -u test1.txt test2.txt > patchfile test1.txt应用patch文件,并备份(test1.txt.orig): ...
- 删除MicrosoftOffice2016的扫尾工作
因为用到一些画流程图之类的工具,想到以前用的Visio挺好用的,就找来安装一下,结果因为装了Microsoft Office2016在安装时报错不断,先说下网上的帖子:用OfficeDeploymen ...
- windows下安装mysql8并修改密码
MySQL下载地址:http://dev.mysql.com/downloads/mysql/ Windows下安装MySQL 我下的是最新版的MySQL,解压后,目录如下: 1.进入dos的命令行, ...
- [BZOJ 3123] [SDOI 2013]森林(可持久化线段树+并查集+启发式合并)
[BZOJ 3123] [SDOI 2013]森林(可持久化线段树+启发式合并) 题面 给出一个n个节点m条边的森林,每个节点都有一个权值.有两种操作: Q x y k查询点x到点y路径上所有的权值中 ...
- [LeetCode] 82. 删除排序链表中的重复元素 II
题目链接 : https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ 题目描述: 给定一个排序链表,删除所有含有 ...
- Java——绘制五角星
Java2D支持通过GeneralPath实现绘制任意的几何形状. 步骤:1)实例化GeneralPath对象 2)调用moveTo()方法锚地开始点坐标 3)调用lineTo()或curveTo() ...
- js防抖和节流优化浏览器滚动条滚动到最下面时加载更多数据
防抖和节流,主要是用来防止过于平凡的执行某个操作,如浏览器窗口变化执行某个操作,监听某个input输入框keyup变化,瀑布流布局时Y轴滚动,图片加载. js函数的防抖 经过一段事件才执行某个操作,如 ...
- Vue Google浏览器插件 Vue Devtools无法使用的解决办法
1.插件安装不必多说 一定要用Vue.js 开发版 Vue.min.js 在控制面板就不会显示 2.本地调试 用的是file://协议 修改插件允许访问文件网址 打上对勾
- shell字符串拼接
name="Shell" url="http://c.biancheng.net/shell/" str1=$name$url #中间不能有空格 str2=&q ...
- 图解NuGet服务器搭建和使用过程
听语音 浏览:0 | 更新:2017-10-31 09:13 | 标签:服务器 1 2 3 4 5 6 7 分步阅读 本篇经验将和大家介绍内网搭建NuGet服务器的步骤,希望对大家的工作和学习有所帮助 ...