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 ...
随机推荐
- 史上最全APP推广渠道
群主做App推广的过程中,有过失败也尝过成功的甜头,渐渐地在APP推广尤其是渠道推广中积累了一些实战经验想同大家分享.如果各位有更好的推广建议,欢迎沟通分享哦! 一.应用商店推广 1.应用市场 ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- C#基本线程同步
0 概述 所谓同步,就是给多个线程规定一个执行的顺序(或称为时序),要求某个线程先执行完一段代码后,另一个线程才能开始执行. 第一种情况:多个线程访问同一个变量: 1. 一个线程写,其它线程读:这种情 ...
- 微信lbs---返回两个经纬度坐标点的距离
微信开发:lbs附近的商家,在数据库里记录商家的坐标,lbs设置里管理搜索半径,查询的时候,查询 客户当前坐标的半径内的所有商家列表.个人喜欢不一样,我选择了执行sql ,毕竟效果高点.微信开发必须得 ...
- 【JavaScript】JavaScript脚本代码的位置及在页面中的执行顺序
三.如何改变Javascript在页面的执行顺序 利用onload <script type="text/javascript">window.onload = f; ...
- [Angular 2] Set Properties on Dynamically Created Angular 2 Components
When you generate Angular 2 components, you’re still able to access the component instance to set pr ...
- 虚拟机VMware 9安装苹果MAC OSX 10.8图文教程
前些天虚拟机VMware Workstation 9出来,相信大家都已经熟悉VM9了,至于MAC OSX 10.8系统,那也是出来一段时间了,本篇文章就是来讲解VMware Workstation 9 ...
- 小白日记48:kali渗透测试之Web渗透-XSS(二)-漏洞利用-键盘记录器,xsser
XSS 原则上:只要XSS漏洞存在,可以编写任何功能的js脚本 [反射型漏洞利用] 键盘记录器:被记录下的数据会发送到攻击者指定的URL地址上 服务器:kali 客户端 启动apache2服务:ser ...
- WPF 之 设置Dialog的父窗体
1.如果弹出窗体(如ChildWindow),调用Show方法,并且设置了其Owner属性: ClassRootWindow { void Foo() { ChildWindow cw = newCh ...
- solrj-WiKi
solrj是一个访问solr的客户端,它提供了一个接口,用于添加.更新.删除索引数据. solrj跨版本兼容 solrj一般保持向后兼容,所以你可以使用新版本的solrj访问老版本的solr服务,也可 ...