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 ...
随机推荐
- ABP框架设置默认语言
在Global.asax文件中设置 private readonly IAbpWebLocalizationConfiguration _webLocalizationConfiguration; p ...
- C++调用Asprise OCR识别图片
在一个识别软件中发现了Asprise OCR的"身影",上官网查了一下相关信息,发现功能挺强大的,识别印刷体应该不错,遗憾的是好像不能识别中文,不过不知道它对扭曲后的英文识别能力怎 ...
- selenide UI自动化进阶二 pageObject实现页面管理
首先定义登录页面,上代码吧 LoginPage.java package com.test.selenium.page; import org.openqa.selenium.By; import s ...
- Daily Scrum02 12.03
Daily Scrum03 12.03 一天过去了,新的一天即将到来,我们组仍旧干劲十足呢~ Member Today's Task Tomorrow's Task 李孟 孟神有点累了呢 task85 ...
- PhpStorm 配置数据库
点击软件右边的 Database
- Spring Boot学习(二):配置文件
目录 前言 方式1:通过配置绑定对象的方式 方式2:@Value("${blog.author}")的形式获取属性值 相关说明 注解@Value的说明 参考 前言 Spring B ...
- java-2018-01-17计划
1.一句英语 包括单词 2.一个java版本的设计模式 参考:https://github.com/iluwatar/java-design-patterns 学习了抽象工厂模式 总结:java的RS ...
- incorrect integer value for column 问题解决
最近在用zend框架,然后装了一个项目,发现注册的时候出现 General error: 1366 Incorrect integer value: '' for column 'user_id' a ...
- CSS的基本使用
CSS的出现就是为了将HTML的内容与样式分离 CSS的书写方式 selector{ key:value } h1{ color: blue; } <!DOCTYPE html> < ...
- doget,doPost在底层走的是service
doget,doPost在底层走的是service 因为在源码上 先执行service方法 然后再调用doget,doPost方法