hdu 1518 Square(深搜+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518
题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时!
#include <iostream>
#include <cstdio>
#include<algorithm>
#include <cstring>
using namespace std;
int ap[],visit[];
int l,n;
int dfs(int len,int gen,int iqq)
{
if (gen==)
return ;
for(int i=iqq; i<n; i++)
{
//cout<<visit[len]<<endl;
if (!visit[i])
{
visit[i]=;
if (len+ap[i]==l)
{
//cout<<len<<endl;
if(dfs(,gen+,))
return ;
}
else if (len+ap[i]<l)
{
//cout<<len<<endl;
if(dfs(len+ap[i],gen,i)) return ;
}
visit[i]=;
}
}
return ;
}
int main ()
{
int t,sum;
while (cin>>t)
{
while (t--)
{
cin>>n;
sum=;
//Max=0;
for (int i=; i<n; i++)
{
cin>>ap[i];
sum+=ap[i];
}
memset(visit,,sizeof(visit));
sort(ap,ap+n);
if (sum%==&&n>=&&ap[n-]<=sum/)
{ l=sum/;
if (dfs(,,))
printf ("yes\n");
else
printf ("no\n");
//cout<<n<<endl;
}
else printf ("no\n");
}
}
}
hdu 1518 Square(深搜+剪枝)的更多相关文章
- hdu 1518 Square 深搜,,,,花样剪枝啊!!!
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- poj1190 生日蛋糕(深搜+剪枝)
题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- ACM 海贼王之伟大航路(深搜剪枝)
"我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...
- POJ-1724 深搜剪枝
这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...
- Block Breaker HDU - 6699(深搜,水,写下涨涨记性)
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- 一本通例题-生日蛋糕——题解<超强深搜剪枝,从无限到有限>
题目传送 显然是道深搜题.由于蛋糕上表面在最底层的半径确认后就确认了,所以搜索时的面积着重看侧面积. 找维度/搜索面临状态/对象:当前体积v,当前外表面面积s,各层的半径r[],各层的高度h[]. 可 ...
- HDOJ/HDU 1015 Safecracker(深搜)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
随机推荐
- Solution to LeetCode Problem Set
Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...
- 【个人训练】(POJ1837)Balance
这几天抓住国庆的黄金时间(因为没有女朋友,天天刷题emmmm 其实还在肝少前还要捞秋刀鱼) ,重点攻克掉几个基本的地方:搜索.dp.图论.这几天的题目应该就是这些范围. 题意 原题的意思大概是这样的, ...
- Ubuntu下使用Git_5
还欠大家最后一篇Git的学习. Git的下一个内容,标签,标签是为了更方便的参考提交而给他表上通俗易懂的名称 Git可以使用两种标签,轻标签和注解标签,打上的标签是固定的,不能向分支那样可以移动位置, ...
- C++知识点 内存占用问题
有一次去面试,谈的挺好的,被人问了一个问题,瞬间暴露自己基础能力弱的弱点了,这里自己记录下,以后慢慢长进. 问题 char test1[]={1,2,3,4}; char test2[]={1,2,3 ...
- argos3-simulator
如何修改控制器: CVector2: class CVector2 { friend class CRotationMatrix2; friend class CTransformationMatri ...
- LCA(最近公共祖先)——LCA倍增法
一.前人种树 博客:最近公共祖先 LCA 倍增法 博客:浅谈倍增法求LCA 二.沙场练兵 题目:POJ 1330 Nearest Common Ancestors 代码: const int MAXN ...
- android http
在Android开发中,Android SDK附带了Apache的HttpClient,它是一个完善的客户端.它提供了对HTTP协议的全面支持,可以使用HttpClient的对象来执行HTTP GET ...
- ExtJS6.0扩展日期选择控件为也可以选择时间
PS:ExtJS自带的日期选择控件只能够选择日期,但是现在的需求需要精确到秒,所以在网上搜索了一些例子(大部分是4.0的)作为参考,然后改出了6.0可用的一个日期时间选择控件. 1.找到extjs6. ...
- UITableView性能优化【本文摘自智车芯官网】
UITableView是个表格视图,可以在表格行空间中添加多个子控件,UITableView继承了UIScrollView,默认状态下可以堆单元格进行滚动,所有的UITableViewControll ...
- [C/C++] C++常见面试题
参考:http://blog.csdn.net/shihui512/article/details/9092439 1.new.delete.malloc.free之间的关系 malloc和free都 ...