Uva_674
You can use deep search to solve this problem. You can enumerate the quantity selected for each non-1 nominal value. The remaining nominal value must be set to 1. In order to make full use of the subproblem solution, we can retain all the subproblems in the computing process. When other results need to be calculated, directly return the record value.
# Include <stdio. h>
# Include < String . H>
# Define Maxd 8000
Int F [maxd] [ 5 ], A [] = { 50 , 25 , 10 , 5 , 1 };
Int N;
Int DFS ( Int Cur, Int St)
{
Int I, A = 0 ;
If (F [cur] [st])
Return F [cur] [st];
If (St = 4 )
Return F [cur] [st] = 1 ;
For (I = 0 ; A [st] * I <= cur; I ++)
A + = DFS (cur-A [st] * I, ST + 1 );
Return F [cur] [st] =;
}
Int Main ()
{
Int I;
Memset (F, 0 ,Sizeof (F ));
For (I = 0 ; I < 5 ; I ++)
F [ 0 ] [I] = 1 ;
While (Scanf ( " % D " , & N) = 1 )
{
Printf ( " % D \ n " , DFS (n, 0 ));
}
Return 0 ;
}