HDU4277 USACO ORZ(dfs+set)
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)
刚看到的时候以为是排列组合一类的问题,看了题解以后才看出其简单的解法,也是暴力解法,题目就是这种目的。。。每种情况挨个试,用set来去重。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include<cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
#include <cctype>
using namespace std;
typedef unsigned long long ull;
#define INF 0xfffffff int l[],n,e[];
set<int> s; //a,b,c是边,k是已经用的边数
void dfs(int a,int b,int c,int k)
{
if(n==k)
{
if((a<=b)&&(b<=c)&&(b+a>c))
{
s.insert(a*+b*+c); //这里为了保证一种形状的唯一性,必须要乘以足够大的数,当b*123时就WA。
} return;
}
dfs(a+l[k],b,c,k+);
dfs(a,b+l[k],c,k+);
dfs(a,b,c+l[k],k+);
return;
} int main()
{
int k,m,q,p;
int T;
cin>>T;
while(T--)
{
s.clear();
memset(l,,sizeof(l));
cin>>n;
for(int i=;i<n;++i)
{
cin>>l[i];
} dfs(,,,); //一定要从0开始,不能dfs(l[0],l[1],l[2],3),这样就没有这三条边组合在一条边上的情况。 cout<<s.size()<<endl; }
return ;
}
HDU4277 USACO ORZ(dfs+set)的更多相关文章
- hdu4277 USACO ORZ
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 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(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+剪枝)
Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...
- hdu 4277 USACO ORZ (dfs暴搜+hash)
题目大意:有N个木棒,相互组合拼接,能组成多少种不同的三角形. 思路:假设c>=b>=a 然后枚举C,在C的dfs里嵌套枚举B的DFS. #include <iostream> ...
- 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 ...
随机推荐
- MVVM知识库总结
1.关于MVVM概念的理解和实际运用中的解析: http://www.cnblogs.com/hielvis/archive/2011/03/22/1991959.html http://msdn.m ...
- UIBezierPathStudyDemo
import UIKit import XCPlayground //创建view let myView = UIView(frame:CGRectMake(0, 0, 300, 200)) //实时 ...
- JavaScript针对Dom相关的优化心得
JavaScript针对Dom相关的优化心得 组内同时总结的关于javascript性能优化注意些节.记录一下. 1. 批量增加 Dom 尽量使用修改 innerHTML 的方式而不是用 append ...
- 剑指 offer set 6 打印从 1 到 N 的所有数
总结 1. 求全排列的变形题, 有些隐晦, 没看出来
- oc-31-多对象的内存管理
在每个OC对象内部,都专门有8个字节的存储空间来存储引用计数器. 引用计数器的常见操作 retain消息:堆内存中对象的计数器变量 +(该方法返回对象本身,要想计数器变量加1就要调用对象的retain ...
- 信号之signal函数
UNIX系统的信号机制最简单的接口是signal函数.signal函数的功能:为指定的信号安装一个新的信号处理函数. #include <signal.h> void (*signal(i ...
- 小凡的Linux主机与时间服务器同步记录
小凡的Linux主机与时间服务器同步记录 导读 我们新安装的Linux主机,如果没有做与互联网服务器时间同步的处理的话,当我们使用date命令的时候,我们就看不到当前的时间,只能看到过去的时间.在我们 ...
- jquery 动态事件绑定(0512)
jquery动态事件绑定,父元素需为静态元素,(不能是动态生成): $("#parent").on("click","#child",fun ...
- SecureCRT 滚动条设置
不久前在Debian下使用kermit时发现kermit有一些优点,比如当串口上不断有信息打印时,仍然可以通过拖动滚动条来查看以前打印的信息,并且滚动条不会滚动到最下面.当按下回车键时,滚动条会自动滚 ...
- MAMP Pro3.5注册码
MAMP这个就不用介绍了,堪称MAC下的苏菲玛索,官方下载地址:https://www.mamp.info/en/mamp-pro/ ,400多大洋,土豪朋友请直接购买吧,正版还是要支持的. 和我 ...