热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

POJ1011Sticks(经典dfs)

Language:Default简体中文SticksTimeLimit: 1000MS MemoryLimit: 10000KTotalSubmissions: 120720 Accepted: 27951DescriptionGeorgetooks

Language:
Sticks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 120720   Accepted: 27951

Description

George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero.

Input

The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.

Output

The output should contains the smallest possible length of original sticks, one per line.

Sample Input

9
5 2 1 5 2 1 5 2 1
4
1 2 3 4
0

Sample Output

6
5

Source



题意:给你紧跟棍子,问可能是哪几根相同的棍子截成的,求可能的棍子的最小值


很难的dfs,剪枝很重要,我也是看别人题解的⊙﹏⊙b汗,解释在代码中




#include
#include
#include
#include
#include
using namespace std;

#define N 105

int a[N],len,n;
int vis[N],sum;

int cmp(int a,int b)
{
    return a>b;
}

bool dfs(int pos,int temp,int cut)
{
    if(cut==sum/len)  //拼凑成功
        return true;

    int i;

    for(i=pos;i






推荐阅读
author-avatar
阿甘正传
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有