Dp,f[i] represents the number of scenarios where 1 to I are placed, G[i] represents the number of scenarios where 1 to I are placed and the leftmost is the valley, you can get the DP equation F[i]=σg[j]*g[i-1-j]*c[i-1][j] (0<=j<i), the number of combinations directly open array will explode, You can use a scrolling array or open a vector to calculate it, not explode.
Code
1#include <cstdio>2#include <vector>3 using namespacestd;4 Const intN =4210;5 intn,p,i,j;6vector<int>C[n];7 Long LongF[n],g[n];8 intMain ()9 {Tenscanf"%d%d",&n,&P); One for(i=0; i<=n;i++) A { -C[i].push_back (1); - for(j=1; j<=i;j++) the { - inttmp=0; -tmp=c[i-1][j-1]; - if(j<=i-1) tmp= (tmp+c[i-1][J])%P; + C[i].push_back (TMP); - } + } Ag[1]=g[0]=1; at for(i=2; i<=n;i++) - for(j=0; j<i;j++) - { -(F[i]+= (g[j]*g[i-1-J])%p*c[i-1][J])%=P; - if(j&1) -(G[i]+= (g[j]*g[i-1-J])%p*c[i-1][J])%=P; in } -printf"%lld", F[n]); to}
bzoj1925 [Sdoi2010] Goblin Tribe