POJ 1011 Sticks (Classic dfs)
Language:DefaultSimplified ChineseSticks
Time Limit:1000 MS |
|
Memory Limit:10000 K |
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 shoshould 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 Source Central Europe 1995 |
Q: Keep your stick up and ask which of the same sticks are cut down to the minimum possible values.
Very difficult dfs, pruning is very important. I am also reading the question of others, and explained it in the code.
# Include
# Include
# Include
# Include
Using namespace std; # define N 105int 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