Http://poj.org/problem? Id = 1252
Calculate the sum of the six coins, F [J] = min (F [J], F [J-data [I] + 1 );
Then, when the value is 0, F [J] = min (F [J], F [J + data [I] + 1) is calculated );
The calculation limit is greater than 100, because there is a change of zero, but it is not very good to determine how large it is.
Code:
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
Using namespace STD;
Const int max = 2500 ;//..
Int data [6], F [Max];
Int main (){
Int t, n, I, j, sum, Max;
Scanf ("% d", & T );
While (t --){
For (I = 0; I <6; I ++)
Scanf ("% d", & Data [I]);
F [0] = 0;
For (I = 1; I <Max; I ++)
F [I] = 2000000;
For (I = 0; I <6; I ++) // sum
For (j = data [I]; j <Max; j ++)
F [J] = min (F [J], F [J-data [I] + 1 );
For (I = 0; I <6; I ++) // subtract
For (j = max-data [I]; j> = 1; j --)
F [J] = min (F [J], F [J + data [I] + 1 );
Sum = max = 0;
For (I = 1; I <= 100; I ++ ){
Sum + = f [I];
If (F [I]> MAX) max = f [I];
}
Printf ("%. 2lf % d \ n", (double) sum/100, max );
}
Return 0 ;}