POJ 1011 Sticks

Source: Internet
Author: User

The problem is to do cry = =
Before we defined all the variables as global variables, the result was always committed by the time RT, and I could not find the fault. It was later changed to local variable AC = =.

D- Sticks (3.4.2)Time limit:MS Memory Limit:10000KB 64bit IO Form At:%i64d &%i64u Submit Status 

id=963 "target=" _blank "style=" Border-bottom:rgb (211,211,211) 1px solid; position:relative; text-align:center; Border-left:rgb (211,211,211) 1px solid; padding-bottom:0px; overflow-x:visible; overflow-y:visible; Text-transform:none; Background-color:rgb (227,228,248); padding-left:0px; padding-right:0px; Zoom:1; Display:inline-block; Font-family:verdana,arial,sans-serif; Color:rgb (85,85,85); Font-size:1em; Border-top:rgb (211,211,211) 1px solid; Font-weight:normal; Margin-right:0.1em; Border-right:rgb (211,211,211) 1px solid; Text-decoration:none; padding-top:0px ">practice   poj 1011

Description

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

Input

The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there is at most 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

95 2 1 5 2 1 5 2 141 2 3 40

Sample Output

65

Main topic:

Arbitrarily split the stick, after the split to try to restore the broken stick to the original state, but he forgot how many of the original wooden sticks and the original how long. Please calculate the minimum possible length of the original stick.



#include <iostream> #include <string.h> #include <algorithm>using namespace Std;int n,num[69];int pd[ 69];int cmp (int a,int b) {return a>b;} int dfs (int len,int s,int nu) {int i;    if (s==0&&nu==0)//Assume the remaining length and the remaining number of sticks is 0. The successful return Len;    if (s==0)//Assuming that the remaining length is 0, then another assignment S=len;    for (i=0;i<n;i++)    {        if (pd[i]==1) continue;        if (S>=num[i])        {            pd[i]=1;            if (Dfs (len,s-num[i],nu-1)) return  len;pd[i]=0;//is assumed to be unsuccessful, the current stick does not use            if (num[i]==s| | S==len) break;            while (num[i]==num[i+1]) i++;        }    } return 0;} int main () {    while (cin>>n&&n)    {int i;int sum;        Sum=0;int len,k;for (i=0;i<n;i++) {cin>>num[i];sum=sum+num[i];} Sort (num,num+n,cmp), for (len=num[0];len<=sum;len++) {memset (pd,0,sizeof (PD)), if (sum%len==0) {K=dfs (len,0,n); if (k) Break;}} cout<<k<<endl;    }    return 0;} /*95 2 1 5 2 1 5 2 141 2 3 40*/



POJ 1011 Sticks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.