HDU1518:Square(DFS)
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
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
Source
#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)的更多相关文章
- HDU1518 Square(DFS,剪枝是关键呀)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- HDU-1518 Square(DFS)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- HDU1518 Square(DFS)
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 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 ...
- 1317: Square(DFS+剪枝)
Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form ...
- hdu Square DFS
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU1518 Square 【剪枝】
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU1518 Square
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #de ...
- POJ 2362 Square DFS
传送门:http://poj.org/problem?id=2362 题目大意: 给一些不同长度的棍棒,问是否可能组成正方形. 学习了写得很好的dfs 赶紧去玩博饼了.....晚上三个地方有约.... ...
随机推荐
- web小技巧
如内容超出单元格,则隐藏style="TABLE-LAYOUT: fixed" 让弹出窗口总是在最上面: <body onblur="this.focus();&q ...
- B - ACboy needs your help(动态规划,分组背包)
B - ACboy needs your help Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- C# 调用C++ DLL 的类型转换
//C#调用C++的DLL搜集整理的所有数据类型转换方式,可能会有重复或者多种方案,自己多测试 //c++:HANDLE(void *) ---- c#:System.IntPtr //c++:Byt ...
- SuperMapPy 批量拼接 GeoTiff影像
影像拼接工具使用说明 一.影像像素位深检查 1.采用开源库GDAL的gdalinfo.exe读取GeoTiff文件的信息,如类型.投影,范围等. 2.采用DOS脚本遍历所有GeoTiff文件,输出各个 ...
- Dialog对话框管理工具类
import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; i ...
- C#连接ACCESS的一个问题
C# 连接ACCESS数据库有时候报 "Microsoft.Jet.Oledb.4.0"没有注册,其实,并不是真的没注册,可能是下面的原因 在菜单 “项目”的最下面 工程属性 菜单 ...
- 查看使用了那种shell
cat /etc/shells root@OpenWrt:/www/cgi-bin# cat /etc/shells/bin/ash
- kafka和flume的对比
摘要: (1)kafka和flume都是日志系统.kafka是分布式消息中间件,自带存储,提供push和pull存取数据功能.flume分为agent(数据采集器),collector(数据简单处理和 ...
- 在C#中使用反射调用internal的方法
MSDN上解释Internal如下: The internal keyword is an access modifier for types and type members. Internal t ...
- 第一天学习oc用xcode做的一个加减乘除 圆的面积计算
#import <Foundation/Foundation.h> //这是oc的框架 @interface jisuan : NSObject //申明一个jisuan这样的类 并继 ...