I am trying to optimize a function of the following form:

$L = \int\_{t=0}^{T}(AR-x)dt$, where A is a system parameter

i.e. I am trying to find the optimum x(t) that minimizes L over all admissible x(t)s. R is related to x using a relation:

$\frac{dR}{dt} = axRY - bR$, where a and b are system parameters and $R(0) = R\_{0}$

$\frac{dY}{dt} = -xRY$

I was looking at this problem from mainly a simulation perspective. There is a whole amount of work that went into showing that x can take only two specific values that minimize the function over any given interval. Now, what I was thinking was to convert the integral into its discrete formulation and do the following:

For $t=1$,
Let $x = x\_{min}$ and calculate $L\_{10}$
Let $x = x\_{max}$ and calculate $L\_{11}$
Finally, choose the one that has the min L.

And then continue with t=2 and so on, in the same way. If I visualize this problem, it is nothing but finding a minimum cost path in a binary tree i.e. something of the following form:

---------------------- $L\_{00}$  

-----------------------/--\---------  

------------------$L\_{10}$----$L\_{11}$----  

-----------------/-----\----/----\-------  

-------------$L\_{20}$-----$L\_{21}$-$L\_{22}$-$L\_{23}$--

and so on until the last T. I am not sure if my thought process of simulating this is in the right direction. Can someone give me some suggestions?