Hdu 1455
#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的更多相关文章
- hdu 1455 Sticks
Sticks Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1455 Sticks(dfs+剪枝)
题目大意: George有许多长度相同的木棍,随机的将这些木棍砍成小木条,每个小木条的长度都是整数单位(长度区间[1, 50]).现在George又想把这些小木棒拼接成原始的状态,但是他忘记了原来他有 ...
- uva 215 hdu 1455 uvalive5522 poj 1011 sticks
//这题又折腾了两天 心好累 //poj.hdu数据极弱,找虐请上uvalive 题意:给出n个数,将其分为任意份,每份里的数字和为同一个值.求每份里数字和可能的最小值. 解法:dfs+剪枝 1.按降 ...
- hdu 1455 N个短木棒 拼成长度相等的几根长木棒 (DFS)
N根短木棒 能够拼成几根长度相等的长木棒 求长木棒的长度 如果答案不止一种 输出最小的 Sample Input95 2 1 5 2 1 5 2 141 2 3 40 Sample Output65 ...
- HDU 1455 http://acm.hdu.edu.cn/showproblem.php?pid=1455
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #de ...
- Sticks HDU - 1455 (未完成)
George took sticks of the same length and cut them randomly until all parts became at most 50 units ...
- HDU 1455 Sticks(经典剪枝)
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- hdu 1455(DFS+好题+经典)
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1258 Sum It Up(dfs+去重)
题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...
随机推荐
- datasnap 授权验证DSAuthenticationManager方法应用
服务端 1.服务端只需要增加DSAuthenticationManager1并且把dshttpservice的AuthenticationManager属性设置为DSAuthenticationMan ...
- js Ajax 跨域请求
一.使用jsonp的方式(只支持get请求) 二.使用cors的方式(支持HTTP的大部分请求方式) 三.apache的转发(修改服务器配置) 没有试验,暂时不详细写!
- jquery的常用知识点
一.用jquery寻找元素 1.选择器 基本选择器: $("*") $("#id") 用id匹配 $(".class") 用class名匹配 ...
- HTML 之轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDFS基本工作机制
- ShuffleNet
ShuffleNet (An Extremely Efficient Convolutional Neural Network for Mobile Devices) —— Face++ shuffl ...
- CS224n(一)
个人博客地址: https://yifdu.github.io/2018/10/30/CS224n%E7%AC%94%E8%AE%B0%EF%BC%88%E4%B8%80%EF%BC%89/#more
- volatile变量,java内存模型
volatile变量提供了最轻量级的同步机制,当一个变量加上volatile修饰时,会具有一下两个特性 https://blog.csdn.net/u011277123/article/details ...
- Boinformatics-2018-10-1-目录
1.基因分析 --Using standard microbiome reference groups to simplify beta-diversity analyses and facilita ...
- 从iOS的图片圆角想到渲染
圆角是一种很常见的视图效果,相比于直角,它更加柔和优美,易于接受.设置圆角会带来一定的性能损耗,如何提高性能是一个需要重点讨论的话题. 大家常见的圆角代码x.layer.cornerRadius = ...