I made the following programming question on stack overflow but the users said it was more of math question. Here it is.
Situation You start with a fixed amount of money, take it as $\$1000$. You have $10$ days to invest it in 4 different banks. You can invest any amount in any number of banks. The rates of interest of the 4 banks are $r_1$, $r_2$, $r_3$ and $r_4$. A thief is know to steal from these banks. The probability of him looting a given bank is given by $p_{(bank,day)}$, so $p_{(3,6)}$ would refer to the probability of him looting Bank 3 on Day 6.
Notes He does not loot more than 1 bank a day. Looted money is not compensated. You do not necessarily have to invest money on each day, or invest anything at all. Money invested has to be done so for a whole number of days, so $3\frac12$ days is not permitted. You can (and should) take any level of risk, provided it is optimal when done on an extremely large amount of trials.
Question Given all rates of interest and all 40 values of $p$, write a program that outputs the amounts to be invested in the 4 banks for each of the 10 days.
I don't think an optimal solution is really possible (in a few seconds), so even a greedy approach (or near-optimal solution) would be helpful.
The fact that the thief can only rob one bank a day becomes irrelevant when we consider large numbers of trials, as everything becomes probabilistic anyway. We can thus treat the probability that the money will be safe in bank $k$ between days $n_{1}$ and $n_{2}$ as:
$$\mathbb{P}[\text{money safe in bank }k \text{ between }n_{1} \text{ and }n_{2}]=1-\sum_{r=n_{1}}^{n_{2}}p_{k,r}$$
You can thus compute this for eack bank $k\in\{1,\dots,5\}$ and for every possible combination $n_{1} < n_{2}$, $n_{2} \in \{1,\dots, 10\}$, $n_{1}\in\mathbb{N}$. To do this exhaustively we have:
$$N=5\left(\sum_{n_{2}=1}^{10}\sum_{n_{1}=1}^{n_{2}}1\right)=5\left(\sum_{n_{2}=1}^{10}\left[n_{2}-1\right]\right)=225$$
Which will not take long to compute at all on a modern computer. You can then calculate the expected return for each of these intervals in terms of initial investment $I$:
$$\mathbb{E}[\text{revenue}\mid \text{bank }k \land n\in[n_{1},n_{2}]]=I(1+r_{k})^{n_{2}-n_{1}} \cdot \mathbb{P}[\text{money safe in bank }k\text{ between }n_{1}\text{ and }n_{2}]$$
You can then compute all the potential expectations of having your money in a bank $k$ (or no bank) in possible intervals $n_{1} < n_{2}$, $n_{2}\in\{1,\dots,10\}$,$n_{1}\in\mathbb{N}$. You can thus work out the maximum possible expectation in an optimal way (presumably there even exists an $\mathcal{O}(1)$ solution if you work it out algebraically on paper).