hdu 4277 USACO ORZ dfs+hash
USACO ORZ
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
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)
3
2 3 4
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+;
const double eps=(1e-),pi=(*atan(1.0)); int num[N],n;
struct hashnum
{
const static int si=1e6+;
vector<LL>v[];
void add(LL x)
{
LL temp=x;
x%=si;
for(int i=;i<v[x].size();i++)
if(v[x][i]==temp)return;
v[x].push_back(temp);
}
}hs;
void dfs(int pos,int a,int b,int c)
{
if(pos>n)
{
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(a+b>c)
{
hs.add(1LL*a*+b);
}
return;
}
dfs(pos+,a+num[pos],b,c);
dfs(pos+,a,b+num[pos],c);
dfs(pos+,a,b,c+num[pos]);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=;i<=hs.si;i++)
hs.v[i].clear();
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&num[i]);
dfs(,,,);
int ans=;
for(int i=;i<hs.si;i++)
ans+=hs.v[i].size();
printf("%d\n",ans);
}
return ;
}
hdu 4277 USACO ORZ dfs+hash的更多相关文章
- 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(DFS暴搜+set去重)
原题代号:HDU 4277 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4277 原题描述: USACO ORZ Time Limit: 5000/1 ...
- 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 ...
- HDU4277 USACO ORZ(dfs+set)
Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...
- hdu4277 USACO ORZ
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
随机推荐
- MySQL建表、插入语句等
不定时更新MySQL的一些基础语句以及出现过的问题 5.10 建表语句 CREATE TABLE `policy_landvalue` ( `id` ) NOT NULL AUTO_INCREMENT ...
- jquery parents() next() prev() 找父级别标签 找同级别标签
html结构 解决方法: jquery parents() 找父级别标签 next() 同级别向下找 prev() 同级别想上找 我这里找的是一个,下面有n个的方法 $(document).read ...
- javascript 窗口宽高滚动
//不加window IE不支持 console.info(window.screenLeft);//IE支持火狐不支持 console.info(window.screenX);//火狐支持,IE不 ...
- PowerPoint使用技巧
1.右键Group两个元素,可以一起移动: 2.Insert 屏幕输入功能: 3.录制旁白: 4.录制完旁白之后可以生成视频: 5.如果不确定所有引用的组件是否可以在别的机器上使用,可以导出只CD,生 ...
- c++代码检测工具
cppcheck是一款静态代码检查工具,可以检查如内存泄漏等代码错误,使用起来比较简单,即提供GUI界面操作,也可以与VS开发工具结合使用. 1.安装 一般会提供免安装版,安装完成后将cppcheck ...
- 十一、无事勿扰,有事通知(2)——KVO
概述 Key-Value-Observe,简称KVO,和上节介绍的Notification师出同门,主要目的都是为了实现观察者模式. 虽说是同门师兄弟,但是各自精通的技艺却是各不相同的. 不像Noti ...
- #WEB安全基础 : HTTP协议 | 0x5 URI和URL
URI(统一资源标识符)和URL(统一资源定位符)相信大家都知道URL吧,我们看看它们有什么区别 URI 长得就像这样 /images/hackr.jepg URL 长得像这样 http://hack ...
- 如何让其他电脑访问到自己的Django项目
1.首先修改setting.py文件 ALLOWED_HOSTS = ['*'] 2.运行时使用该命令 python3 manage.py runserver 0:8000 备注:如果上* 为固定的i ...
- c#中可变参数(params关键字的使用)
一.params 是C#开发语言中关键字, params主要的用处是在给函数传参数的时候用,就是当函数的参数不固定的时候. 在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中 ...
- 把ArrayList集合中的字符串内容写到文本文件中
list列表数据导出到指定路径文本文档中 public String getSDCardPath() { String sdCard = Environment.getExternalStorage ...