This problem is much easier to think about if you draw a tree of possible outcomes.

Define E(x, y) to be your combined earning on gambling after A wins x matches and B wins y matches. Define G(x, y) to be the bet you want to put on team B for the next match.

Assume there is only one match, then you should bet $1m on team B. So E(0, 0) = 0. G(0, 0) = $1m.

Assume whoever wins two matches first becomes the champion. It's obvious E(1, 1) = 0. G(1, 1) = $1m. Now let's think about E(0, 1) and G(1, 0). If A wins the next match, you want the combined earning to be E(1, 1) = 0. So E(0, 1) - G(0, 1) = 0. If B wins and becomes the champion, you want your combined earning to be $1m to acheive the final objective. So E(0, 1) + G(0, 1) = $1m and thus E(0, 1) = $500K and G(0, 1) = $500K. With similar reasoning, E(1, 0) = -$500k and G(1, 0) = $500K. Finally in order to get to E(1, 0) and E(0, 1), you have to bet $500K at the beginning so G(0, 0) = $500K.

Assume whoever wins three matches first becomes the champion. Based on the above reasoning, E(1, 1) = 0, G(1, 1) = $500K, E(1, 2) = $500K, and G(1, 2) = $500K. Therefore, E(0, 2) = $750K and G(0, 2) = $250K in order to make E(0, 3) = $1m. Since we have E(0, 1) + G(0, 1) = E(0, 2) = $750K and E(0, 1) - G(0, 1) = E(1, 1) = 0, we have E(0, 1) = $375K and G(0, 1) = $375K. ... ...

We can repeated the same thing for more matches (the real NBA) ... ... ...