#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. [报错]编译报错:clang: error: linker command failed with exit code 1及duplicate symbol xxxx in错误解决方法之一

    今天添加了一个新类(包括m,h,xib文件),还没有调用,—编译遇到如下错误,根据错误提示, duplicate symbol param1 in: /Users/xxxx/Library/Devel ...

  2. webservice接口问题:Payload: No message body writer has been found for class domain, ContentType: application/xml

    当在使用cxf-rs的webservice的时候,有时候在传输数据,会发生这种错误 错误代码: Response-Code: 500 Content-Type: text/plain Headers: ...

  3. flask中的blueprint

    https://blog.csdn.net/sunhuaqiang1/article/details/72803336

  4. Mac 下,Redis(集群)的安装和配置

    1. Redis 安装步骤 1. 到github下载redis,我下载的是3.0.4 下载地址:GitHub 2. 将下载下来的redis-3.0.4.tar.gz拷贝到 /usr/local 目录下 ...

  5. 看我学习Apache+php+wordpress+phpMyAdmin的搭配配置

    开场白:我不是这方面的"专家"或"菜鸟",因为我不懂,别问我为什么,我只是心血来潮好奇,东拼西凑写了这些文字. 1.php的配,使用免安装版本,要进行的设置, ...

  6. Linux-vim与ssh客户端

    一.vim使用 Linux系统下标准的编辑器,他就相当于windows系统中的记事本一样,它的强大不逊色于任何最新的文本编辑器. (1)vim安装 (2)vim使用:操作模式  一般模式(默认模式,不 ...

  7. 使用jQuery创建节点、将节点插入到指定的位置

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. 转: MYSQL获取更新行的主键ID

    在某些情况下我们需要向数据表中更新一条记录的状态,然后再把它取出来,但这时如果你在更新前并没有一个确认惟一记录的主键就没有办法知道哪条记录被更新了. 举例说明下: 有一个发放新手卡的程序,设计数据库时 ...

  9. JQuery点击标题实现div的收缩

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. 63. Unique Paths II(有障碍的路径 动态规划)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...