Square

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 88   Accepted Submission(s) : 37

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square?

Input

The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number of sticks. M integers follow; each gives the length of a stick - an integer between 1 and 10,000.

Output

For each case, output a line containing "yes" if is is possible to form a square; otherwise output "no".

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

Source

University of Waterloo Local Contest 2002.09.21

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int t,i,j,n,m,flag,sum,ans;
int vis[],a[];
int cmp(int a,int b)
{
return a>b;
}
void dfs(int k,int l,int edge)
{
if(edge==)
{
flag=;
return;
}
// if(flag) return;
for(int i=k;i<=n;i++)
if (!vis[i])
if (l+a[i]<=sum)
{
vis[i]=;
if (l+a[i]==sum) dfs(,,edge+);
else dfs(i+,l+a[i],edge);
if(flag) return;
vis[i]=;
}
return;
}
int main()
{ scanf("%d",&t);
for(;t>;t--)
{
scanf("%d",&n);
sum=;
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
} if (sum%!=)
{
printf("no\n");
continue;
} sort(a+,a++n,cmp);
sum=sum/; if (a[]>sum)
{
printf("no\n");
continue;
}
memset(vis,,sizeof(vis));
flag=;
dfs(,,);
if(flag) printf("yes\n");
else printf("no\n");
}
return ;
}

HDU1518:Square(DFS)的更多相关文章

  1. HDU1518 Square(DFS,剪枝是关键呀)

    Square Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  2. HDU-1518 Square(DFS)

    Square Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  3. HDU1518 Square(DFS)

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. HDU1518 Square(DFS) 2016-07-24 15:08 49人阅读 评论(0) 收藏

    Square Problem Description Given a set of sticks of various lengths, is it possible to join them end ...

  5. 1317: Square(DFS+剪枝)

    Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form ...

  6. hdu Square DFS

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. HDU1518 Square 【剪枝】

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  8. HDU1518 Square

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #de ...

  9. POJ 2362 Square DFS

    传送门:http://poj.org/problem?id=2362 题目大意: 给一些不同长度的棍棒,问是否可能组成正方形. 学习了写得很好的dfs 赶紧去玩博饼了.....晚上三个地方有约.... ...

随机推荐

  1. C# 在word文档中复制表格并粘帖到下一页中

    C# 在word文档中复制表格并粘帖到下一页中 object oMissing = System.Reflection.Missing.Value;            Microsoft.Offi ...

  2. 【实验室笔记】C#上位机学习笔记

    用C#编写上位机,基本流程是[1]串口配置,[2]串口发送数据,[3]串口接收数据. [1]串口配置 串口的属性配置包括: No.1串口端口号 No.2串口波特率 No.3串口数据位 No.4串口停止 ...

  3. SQL Server 2012中快速插入批量数据的示例及疑惑

    SQL Server 2008中SQL应用系列--目录索引 今天在做一个案例演示时,在SQL Server 2012中使用Insert语句插入1万条数据,结果遇到了一个奇怪的现象,现将过程分享出来,以 ...

  4. C# 网上收集的一些所谓的开源项目

    C#开源 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7- ...

  5. js键盘键值大全

    原文地址:http://blog.csdn.net/avenccssddnn/article/details/7950524 js键盘键值 keycode 8 = BackSpace BackSpac ...

  6. 《JS权威指南学习总结--4.9.3in和instanceof运算符》

    内容要点: 一.in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数数值的属性名,那么表达式返回true. 例如: va ...

  7. eclipse4.3 安装tomcat8

    Go to the WTP downloads page, select the 3.6.0 version , and download the zip (under Traditional Zip ...

  8. innerhtml 和value值有什么区别

    value 值写在标签里面的,innerHTML写在<button type="button" onclick="myFunction()">Try ...

  9. APP页面设计

  10. 终于购入Mac mini,发现HDMI接口与显示器不兼容,网购了一个VGA转换插头

    Mac mini买到了,最便宜的i5,$647,足够了. 发现路边捡的显示器没有HDMI接口,所以在学校图书馆问了一下IT 技术支持,给我推荐了ebay上$10块钱的转换器. 名字叫 Mini Dis ...