#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. JavaScript中的原型与原型链

    一直对JavaScript的原型与继承不了解,参考<JavaScript权威指南(第六版)>和<JavaScript高级程序设计(第三版)>对这个点的知识做个整理,方便自己记忆 ...

  2. linux定时查询mysql数据库并把结果保存到新表 然后备份数据库

    脚本文件名:myshell内容如下: #!/bin/bash # mysql用户名 username="root" # mysql密码 password="root&qu ...

  3. MySQL对指定字段进行加密(双向加密)

    1:建表 test create table test( name varchar(200), value blob ); 插入数据 使用 ENCODE 加密: ,ENCODE('加密字段值', '钥 ...

  4. C# 中利用 Conditional 定义条件方法

    利用 Conditional 属性,程序员可以定义条件方法.Conditional 属性通过测试条件编译符号来确定适用的条件.当运行到一个条件方法调用时,是否执行该调用,要根据出现该调用时是否已定义了 ...

  5. Git添加本地项目出现fatal: unable to get credential storage lock: File exists

    把本地项目初始化之后上传到github上出现问题:fatal: unable to get credential storage lock: File exists 解决办法:是因为我上传用的git帐 ...

  6. 谷歌浏览器不能打开本地HTML文件

    打开浏览器右上角菜单——>更多工具——>扩展程序——>将Axure RP Extension For Chrome 0.62.crx文件拖入——>成功后,勾选相关选项 文件的下 ...

  7. Spring基本功能-依赖注入

    一.Spring的依赖注入(DI) 1.1 xml形式注入 (1)普通变量的注入 //普通变量的注入,xml配置property,实体类配置set方法注入 <bean id="pers ...

  8. ipython安装(python3.6.1)

    之前一直是在Python2.7环境下装的ipython,今天想在Python3环境下安装,主要是为了方便测试,按tab键可以补全,显示导入模块的方法. 1.首先安装Python3.6.1 wget h ...

  9. 在DLL编程中,导出函数为什么需要extern "C"

    转自:http://blog.csdn.net/zhongjling/article/details/8088664 一般来讲,在DLL编程过程中,对于导出的函数前 都需要加入 extern “C”, ...

  10. 激活webstorm(作为一个伪前端,偶尔用用)

    推荐博客:https://blog.csdn.net/voke_/article/details/76418116 我试的方法一.