Write a function int Foo (int n). For the given n, obtain the number of combinations for any {x, y, z}> = 0, 1x + 2y + 5z = n.
# Include <iostream>
Using NamespaceSTD;
Int Foo1 ( Int N)
{
Int Count = 0 ;
For ( Int Z = 0 ; Z <= N/5 ; Z ++)
{
For ( Int Y = 0 ; Y <= (n- 5 * Z )/ 2 ; Y ++)
{
For (Int X = 0 ; X <= (n- 5 * Z- 2 * Y); X ++)
{
Count ++;
} // This loop can be replaced with Count + = N- 5 * Z- 2 * Y + 1
}
}
Return Count;
}
Int Foo2 ( Int N)
{
Int Count = 0 ;
For ( Int Z =0 ; Z <= N/ 5 ; Z ++)
{
For ( Int Y = 0 ; Y <= (n- 5 * Z )/ 2 ; Y ++)
{
Count + = N- 5 * Z- 2 * Y + 1 ;
} // This loop can be replaced, and Y is an incremental series.
}
Return Count;
}
int foo3 ( int N)
{< br> int COUNT = 0 ;
for ( int Z = 0 ; Z <= N/ 5 ; Z ++)
{< br> count + = (n- 5 * z + 2 ) * (N- 5 * z + 2 )/ 4 ;
}< br> return count;
}
IntMain ()
{
Cout <foo1 (10) <Endl;
Cout <foo2 (10) <Endl;
Cout <foo3 (10) <Endl;
System ("Pause");
Return 0;
}