I finally had a difficult question on my own (n_n)
It is said that it is a cut-off question, but my pruning is still to be improved. The following practices almost time limitted (985 ms)
My own ideas:
DFS search question, which is the total product of the current denominator, the number already exists, and the denominator value of the previous layer.
Returns false when the number already exists equal to A. Otherwise, the denominator value from the previous layer is the next score.
Check whether the conditions are met. If yes, add one.
# Include <iostream>
# Include <cmath>
Using namespace STD;
# Define x 1e-8
Int p, q, A, N;
Int ans;
Bool DFS (double CS, int ca, int CN, int CQ)
{// The remaining shard value, which is the total product of the current denominator. The number already exists. The denominator value of the previous layer.
If (CN = N)
Return false;
Int flag = 0;
For (Int J = CQ; j * Ca <= A; j ++)
{
If (FABS (cs-1.0/J) <X)
{// Because the current operation is successful, setting the flag indicates that the operation is successful, and the returned value is true.
Ans ++;
Flag = 1;
}
If (cs-1.0/j> 0 & DFS (cs-1.0/J, Ca * j, CN + 1, J ))
Flag = 1; // because the current operation is successful, setting the flag indicates that the operation is successful, and the returned value is true.
}
If (FLAG)
Return true;
Else
Return false;
}
Int main ()
{
Freopen ("sum. In", "r", stdin );
Freopen ("sum. Out", "W", stdout );
While (CIN> P> q> A> n, p | q | A | N)
{
Ans = 0;
DFS (p * 1.0/Q, 1, 0, 1 );
Cout <ans <Endl;
}
Return 0;
}