HDU 1545 - 01-K Code

Problem : Find the number of 01 strings, s.t. any consequtive substring doen't have abs(num(0)-num(1))>m.
Solution : Let f[i][j][k] to be the number of valid 01 strings such that it length i, the maximum larger of 1s than 0s ended at tail is j, the maximum larger of 0s than 1s ended at tail is k. Then f[i][j][k]=sum(f[i-1][j+1][k-1](add 0, if j!=m), f[i-1][j-1][k+1](add 1, if k!=m), f[i-1][j][k-1](add 0, if j=0), f[i-1][j-1][k](add 1, if k=0)).
Proof:
1)Any valid string of length i must in only one of the set in f[i]. (contradiction)

2)Using reduction. start from f[0][0][0]=1, f[0][i][j]=0 for (i!=0 or j!=0). Prove the following set must be the union of previous set. and the correctness holds.