#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring> using namespace std;
int n, targetnum, targetlen;
int sumlen = 0;
int stick[1000];
bool vis[1000]; bool cmp(int a, int b){
return a > b;
}
void init(){
sumlen = 0;
for(int i = 0 ; i < n ; i++){
cin >> stick[i];
sumlen += stick[i];
}
memset(vis,0,sizeof vis);
sort(stick,stick+n,cmp);
} bool dfs(int cnt, int len , int pos){
if(cnt == targetnum)
return true;
if(len == targetlen)
return dfs(cnt+1,0,0);
for(int i = pos ; i < n ; i++){
if(!vis[i] && len + stick[i] <= targetlen){
vis[i] = 1;
if(dfs(cnt,len+stick[i],i+1))
return true;
vis[i] = 0;
if(len == 0) return false;
while(i+1<n && stick[i] == stick[i+1])
i++;
}
}
return false;
} void solve(){
int ans = 0;
for(int i = 1; i <= sumlen ; i++){
memset(vis,0,sizeof vis);
if(sumlen % i == 0){
targetnum = i;
targetlen = sumlen / i;
}
if(dfs(0,0,0))
{
ans = targetlen;
}
}
cout << ans << endl;
} int main(){
while(cin >> n && n){
init();
solve();
// cout << targetnum << endl;
}
return 0;
}

Hdu 1455的更多相关文章

  1. hdu 1455 Sticks

    Sticks Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. hdu 1455 Sticks(dfs+剪枝)

    题目大意: George有许多长度相同的木棍,随机的将这些木棍砍成小木条,每个小木条的长度都是整数单位(长度区间[1, 50]).现在George又想把这些小木棒拼接成原始的状态,但是他忘记了原来他有 ...

  3. uva 215 hdu 1455 uvalive5522 poj 1011 sticks

    //这题又折腾了两天 心好累 //poj.hdu数据极弱,找虐请上uvalive 题意:给出n个数,将其分为任意份,每份里的数字和为同一个值.求每份里数字和可能的最小值. 解法:dfs+剪枝 1.按降 ...

  4. hdu 1455 N个短木棒 拼成长度相等的几根长木棒 (DFS)

    N根短木棒 能够拼成几根长度相等的长木棒 求长木棒的长度 如果答案不止一种 输出最小的 Sample Input95 2 1 5 2 1 5 2 141 2 3 40 Sample Output65 ...

  5. HDU 1455 http://acm.hdu.edu.cn/showproblem.php?pid=1455

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

  6. Sticks HDU - 1455 (未完成)

    George took sticks of the same length and cut them randomly until all parts became at most 50 units ...

  7. HDU 1455 Sticks(经典剪枝)

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  8. hdu 1455(DFS+好题+经典)

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. hdu 1258 Sum It Up(dfs+去重)

    题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...

随机推荐

  1. Unable to locate parent package [json-default]

    Unable to load configuration. - [unknown location] Caused by: Unable to locate parent package [json- ...

  2. MapReduce分区和排序

    一.排序 排序: 需求:根据用户每月使用的流量按照使用的流量多少排序 接口-->WritableCompareable 排序操作在hadoop中属于默认的行为.默认按照字典殊勋排序. 排序的分类 ...

  3. type为number的<input>标签 type和size属性失效

    html5中input的type属性增的可取值新增几种,对于不支持这几种新增值的浏览器会统一解析为text类型. Firefox.ie9不支持

  4. react es6语法 之 “ ... ” (扩展运算符)

    扩展运算符(…)用于取出参数对象中的所有可遍历属性,拷贝到当前对象之中 let bar = { a: 1, b: 2 }; let baz = { ...bar }; // { a: 1, b: 2 ...

  5. Elasticsearch提示low disk watermark [85%] exceeded on [UTyrLH40Q9uIzHzX-yMFXg][Sonofelice][/Users/baidu/Documents/work/soft/data/nodes/0] free: 15.2gb[13.4%], replicas will not be assigned to this node

    mac本地启动es之后发现运行一段时间一分钟就能打印好几条info日志: [--13T10::,][INFO ][o.e.c.r.a.DiskThresholdMonitor] [Sonofelice ...

  6. python数据分析基础——numpy和matplotlib

    numpy库是python的一个著名的科学计算库,本文是一个quickstart. 引入:计算BMI BMI = 体重(kg)/身高(m)^2假如有如下几组体重和身高数据,让求每组数据的BMI值: w ...

  7. Mybatis框架学习总结-调用存储过程

    设计需求 查询数据库,查询得到男性或女性的数量,如果传入的参数是0查询女性,否则查询男性. 准备数据库表和存储过程 1.准备person表: CREATE TABLE person( id INT P ...

  8. PAT 1093 Count PAT's[比较]

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  9. JVM类加载器工作流程

    类加载器 classloader:谈到类加载,不得不提的就是负责此项工作的类加载器classloader,classloader的职责是将Java源文件编译后的字节码文件加载到内存中去执行. 类加载至 ...

  10. 小程序页面链接-navigator(导航)

    navigator-页面链接-通过设置open-type的值来确定页面的打开方式. <view class="btn-area"> <navigator url= ...