Seeing the first reaction of this problem, the problem is connected with an example of petition. (although it was later proved that they were not linked.) So my first thought was to add in from N to 11. Although it's really not very good.
and start the membrane. .................................... What a shame!
You can prove it first. An initial descending jitter subsequence 1~n can be changed to an ascending form by N-xi + 1 (the value of Xi as the first bit).
And then, using this property,
Set F[I][J] For length I, starting with 1~j and ascending (if you want to ask me why it is rising you can push it yourself, I can't push it out anyway. ) (The answer is as good as the output).
Recursive f[i][j] = f[i][j-1] + f[i-1][i-j]
F[I][J-1] is the beginning of 1~j-1. So obviously F[i-1][i-j] is starting with J. How to deduce it?
If you start with J and the sequence is 1~i, it starts up. So the second bit has a value range of j+1~i and because it is a jitter subsequence. Then the second bit starts to fall. But what do we ask for (or is there a rise in the form of expression) to fall?
We can turn the descent into ascending by the nature of the beginning. If the initial value range is j+1 ~ I then through N-xi + 1 conversion, the beginning of the range of values becomes 1 ~ i-j. (If the previous representation is rising, there will be a problem here.) So it is obvious that f[i-1][i-j], as to why the i-1, because the length of the sequence is only i-1. That's it.
1#include <cstdio>2#include <iostream>3 #defineRep (i,j,k) for (register int i = j; I <= K; i++)4 using namespacestd;5 6InlineintRead () {7 ints =0, t =1;Charc =GetChar ();8 while(!isdigit (c)) {if(c = ='-') T =-1; c =GetChar ();}9 while(IsDigit (c)) s = S *Ten+ C- -, C =GetChar ();Ten returnS *T; One } A - intf[2][4201]; - the intMain () { - intn = read (); Registerintp = Read (), now =1, pre =0; -f[now][1] =1; -Rep (I,2, N) { + swap (now,pre); -Rep (J,1, I) { +F[NOW][J] = f[now][j-1] + f[pre][i-j]; A if(F[now][j] >= p) f[now][j]-=p; at } - } -COUT<<F[NOW][N] *2% p<<Endl; - return 0; -}
1925: [Sdoi2010] Goblin Tribe DP, jitter sub-sequence