I'm a weak B.
In the beginning, it was thought that for a number, half a cent would be better than the other allocation scheme, and then eventually
Half-points are not necessarily the best allocation scheme, for example, 9 may be divided into 3 3 better than half
I do not know how those Daniel think, I read the first code, he enumerated the maximum value of the final state, he is how to think about the problem?
The following I changed CAI's brute force code, plus the enumeration of each sub-method, currently can be too small data, big data timeout should
1#include <cstdio>2#include <iostream>3#include <cstring>4 5 using namespacestd;6 7 inta[1005];8 intN;9 Ten intMintime (inti) { One intJ; A for(j = i; J >=1; j-- ) { - if(A[j] >0) - Break; the } - if(J <=1) { - return 1= = J && A[j] >0?1:0; - } + - intAns =J; + for(intx =1; X <= (J >>1); ++x) { AA[X] + =A[j]; atA[j-x] + =A[j]; - intTMP = A[j] + mintime (J-1); -ans = ans > tmp?Tmp:ans; -A[X]-=A[j]; -A[j-x]-=A[j]; - } in - returnans; to } + - intMain () { the intT; *CIN >>T; $ for(intCAS =1; CAS <= T; ++CAs) {Panax NotoginsengCIN >>N; -Memset (A,0,sizeof(a)); the for(inti =0; I < n; ++i) { + intp; ACIN >>p; the++A[p]; + } - intAns = mintime ( +); $cout <<"Case #"<< CAs <<": "<< ans <<Endl; $ } - return 0; -}
The following is the code of the great God, I leave it to commemorate
1 intMin =10000;2 for(intLim =1; Lim <= Counts.length; lim++)3 {4 intMoves =0;5 for(inti =0; i < counts.length; i++)6Moves + = ((I-1)/Lim) *counts[i];//This i-1 I'm drunk, too.7 if(Moves + Lim <min)8Min = moves +Lim;9}
GCJ2015 problem B. Infinite House of Pancakes