HDU1518 Square(DFS) 2016-07-24 15:08 49人阅读 评论(0) 收藏
Square
Problem Description
Input
Output
Sample Input
3
4 1 1 1 1
5 10 20 30 40 50
8 1 7 2 6 4 4 3 5
Sample Output
yes
no
yes
————————————————————————————————————————————————————————————
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int a[250], vis[205], sum, l, n; int dfs(int x, int pos, int len)
{
if (x == 3)
return 1;
int i;
for (i = pos; i >= 0; i--)
{
if (!vis[i])
{
vis[i] = 1;
if (len + a[i]<l)
{
if (dfs(x, i - 1, len + a[i]))
return 1;
}
else if (len + a[i] == l)
{
if (dfs(x + 1, n - 1, 0))
return 1;
}
vis[i] = 0;
}
}
return 0;
} int main()
{
int t, i, j;
scanf("%d", &t);
while (t--)
{
sum = 0;
scanf("%d", &n);
for (i = 0; i<n; sum += a[i], i++)
scanf("%d", &a[i]);
l = sum / 4;
memset(vis, 0, sizeof(vis));
sort(a, a + n);
if (l * 4 != sum || n<4 || l<a[n - 1])//剪枝
{
printf("no\n");
continue;
}
if (dfs(0, n - 1, 0))
printf("yes\n");
else
printf("no\n");
} return 0;
}
HDU1518 Square(DFS) 2016-07-24 15:08 49人阅读 评论(0) 收藏的更多相关文章
- Apache+tomcat的整合 分类: C_OHTERS 2014-05-07 15:08 293人阅读 评论(0) 收藏
http://blog.csdn.net/stefyue/article/details/6918542 为什么要做这个整合呢?当然,首先想到是就是Apache和Tomcat的区别.正因为有区别,有各 ...
- Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
- max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...
- HDU1426 Sudoku Killer(DFS暴力) 2016-07-24 14:56 65人阅读 评论(0) 收藏
Sudoku Killer Problem Description 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会 ...
- HDU1501 Zipper(DFS) 2016-07-24 15:04 65人阅读 评论(0) 收藏
Zipper Problem Description Given three strings, you are to determine whether the third string can be ...
- 浅谈声明与定义的区别 分类: C/C++ 2015-06-01 15:08 157人阅读 评论(4) 收藏
以下代码使用平台是VS2012. 清楚明白声明与定义是一名合格的程序猿的基本要求. 本人认为,C++编码过程中谈及"声明"和"定义"是因为我们要使用一个变量.类 ...
- Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏
1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 苹果应用商店AppStore审核中文指南 分类: ios相关 app相关 2015-07-27 15:33 84人阅读 评论(0) 收藏
目录 1. 条款与条件 2. 功能 3. 元数据.评级与排名 4. 位置 5. 推送通知 6. 游戏中心 7. 广告 8. 商标与商业外观 9. 媒体内容 10. 用户界面 11. 购买与货币 12. ...
随机推荐
- 利用Spark-mllab进行聚类,分类,回归分析的代码实现(python)
Spark作为一种开源集群计算环境,具有分布式的快速数据处理能力.而Spark中的Mllib定义了各种各样用于机器学习的数据结构以及算法.Python具有Spark的API.需要注意的是,Spark中 ...
- js 获取input选择的图片的信息
1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...
- afinal框架下 ViewInject的使用
1.可以在BaseActivity界面onCreate 方法setContentView后加上该语句. initInjectedView(this); 2.@ViewInject(id=R.id.v_ ...
- Mysql InnoDB 数据更新 锁表
一.数据表结构 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `jx_attach` ( `attach_id` int(11) NOT NULL AUTO_INCREMEN ...
- EasyUI 导出页面到Excel中
<script type="text/javascript"> <!-- js --> /*================================ ...
- Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied.
访问路径被拒绝 我解决了这个设置: IIS>应用程序池> [您的站点]>高级设置...>标识>内置帐户> LocalSystem
- <cctype>库
http://www.cplusplus.com/reference/cctype/ 函数名称 返回值 isalnum() 如果参数是字母数字,即字母或数字,该函数返回true isalpha() 如 ...
- 56. Merge Intervals (Array; Sort)
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- TOYS(叉积)
TOYS http://poj.org/problem?id=2318 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 193 ...
- 3-QT程序运行时报错E:\SogouInput\6.7.0.0329\程序异常终止,该怎么解决?
https://bbs.csdn.net/topics/390653779 出现这个错误的原因,使用声明的对象时,没有使用new对对象进行实例化. 包括:数组.