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 limit 性能问题分析
问题重现 // todo 参考文章: MySQL 单表分页 Limit 性能优化 Scalable MySQL: Avoid offset for large tables 证明为什么用limit时, ...
- 通过ALT+F9关键CALL追踪注册码
1)弹出关键字对话框,记录关键字注册失败,请检查···· 2)使用PEID查壳 3)peid提示无壳 4)发送到OD 5)F9使od运行 5.1)继续输入用户 5.2)使其暂停 5.3)点击调试中的执 ...
- F#周报2019年第7期
新闻 Visual Studio 2019预览版3,F#性能修复 Bolero 0.3发布,HTML模版热加载 Fantomas在线升级至Fantomas 2.9.2 使用F#开发的随机访问Excel ...
- F#周报2019年第2期
新闻 Rider上的拼写助手,对未使用引用的代码分析及更多F#相关特性的更新 .NET开源革命开始 ML.NET 0.9发布记录 测试驱动的集成开发环境 Giraffe在GitHub上超过了1000个 ...
- bat杂记 cmd
强制复制覆盖 copy f:\temp1.txt f:\temp2.txt /y 删除 del f:\temp1.txt 删除任务aa1 schtasks /Delete /TN aa1 /F cmd ...
- php 延迟静态绑定: static关键字
abstract class DomainObject { public static function create() { return new self(); } } class User ex ...
- 部署WEB项目到服务器(三)安装mysql到linux服务器(Ubuntu)详解
突发奇想,想在自己电脑上部署一个web网站. 1,首先是下载一个适合自己已安装服务器版本的mysql数据库. 这里使用网上的链接http://dev.mysql.com/downloads/mysql ...
- 【English】【托业】【四六级】写译高频词汇
大家都知道,四六级翻译每次考的话题不可能原句直接重复,但是,在研究了近几年的四六级真题后,我们惊奇地发现: 写译词汇在重复考! 写译词汇在重复考! 写译词汇在重复考! 因此,小编为大家整理了四六级写译 ...
- js/jquery 元素是否存在
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>spli ...
- Flask主要知识点
Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...