"Search" small sticks Title DescriptionGeorge had some of the same long little sticks, and he cut the sticks into pieces at random, until the length of each paragraph was no more than 50.
Now, he wants to splice the sticks into the original, but forgets how many sticks and lengths they had at the beginning.
Given the length of each small stick, programming helps him figure out the minimum possible length of the original stick.
Inputthere are two lines.
The first behavior of a single integer n indicates the total number of small wooden cabinets that have been seen, where n≤60, the second act n a positive integer separated by a blank, indicates the length of n with the small stick.
Outputonly one row, which represents the minimum possible length of the requested original stick. Sample input
95 2 1 5 2 1 5 2 1
Sample output
6
Enumerate and determine the length between Max (A[0......n-1]) ~sum (a[0]+a[1]+......+a[n-1]) L and sum%l = = 0
If you can compose num small sticks, and num = = SUM/L will succeed.
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<queue>using namespacestd;Const intMAXN = the;intA[MAXN], n, Sum, M, aim, B[MAXN];BOOLSlove (intIintLenintnum) { if(i = = n && num = = SUM/aim) { return true; } if(i = = N)return false; for(intj =0; J < N; J + +) { if(!B[j]) { if(A[j] + len = =aim) {B[j]=true; Slove (i+1,0, num+1); B[J]=false; } if(A[j] + len <aim) {B[i]=true; Slove (i+1, Len +a[j], num); B[J]=false; } } }}intMain () {scanf ("%d", &N); Sum= m =0; for(inti =0; I < n; i++) {scanf ("%d", &A[i]); Sum+=A[i]; M=Max (M, A[i]); } for(aim = m; aim <= sum; aim++) { if(sum% aim = =0) {memset (b,false,sizeof(b)); if(Slove (0,0,0) {printf ("%d\n", AIM); Break; } } } return 0;}
"Search" small sticks