[ again, this is for my personal usage. USACO solution is a little bit too difficult to understand, at least for me. The explanation below is easier to understand. ] - BTW, if anybody knows how to make a blog private, please write the instruction in the comment section.
problem statement: http://usaco.org/index.php?page=viewproblem2&cpid=1069
dp(a,b,c) : number of ways from a -> b, the highest button used is upto c
first, after we press the button, we can stay at b, so dp(a,b,c) += dp(a,b,c-1)
or we go a -> r -> b with max button of c. In this case,
between a->r, we find a point x with max button c-1. Then from x -> r the worse you can do is press button c
between r -> b, since c-1 is reset and available, the worse we can do is press c-1 to a point y, then y->b use max button of c-1
then define
dp1(a,r,c-1) is sum over all x, where x->r, dp(a,x,c-1) dp2(r,b,c-1) is sum over all y, where y->r, dp(y,b,c-1)
- then dp(a,b,c) += sum over r, dp1 * dp2
Then we put constrain on (bs,s) and (bt,t)
use dp[2][2](a,b,c), 0/1 is whether s/t constrain is used or not
Then we put constrain on (bs,s) and (bt,t)
use dp[2][2](a,b,c), 0/1 is whether s/t constrain is used or not
doing the same, a -> b is sum over r of a -> r -> b
but a->r is pinned at the start, and r->b is pinned at the end