http://acm.hdu.edu.cn/showproblem.php?pid=5151
Test instructions: A total of n chairs, and then there are N students to sit in turn, meet the following three conditions can not sit up, 1: The chair next to the left chair also has a right chair, 2: The chair is sitting next to the seat, 3: The chair next to the color of the chair.
Ask if everyone is sitting up and there's a lot of things.
DP[I][J] Indicates the number of conditions that the interval [i,j] satisfies. This problem is an interval DP. A large interval is processed into a number of small intervals.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineMoD 10000000075 #definell Long Long6 using namespacestd;7 8 intN;9 inta[ $];Tenll c[ $][ $]; Onell dp[ $][ $]; A - voidInti () - { the for(intI=0; i<=101; i++) - { -c[i][0]=1; - for(intj=1; j<=i; J + +) + { -C[i][j]= (c[i-1][j]+c[i-1][j-1])%MoD; + } A } at } - -ll Get_num (intXinty) - { - if(x>y)return 0; - if(Dp[x][y])returnDp[x][y]; in if(x==y)returndp[x][y]=1; -ll ans=0; to for(inti=x+1; i<y; i++) + { - if(a[i-1]!=a[i+1])Continue; theAns+=get_num (x,i-1) *get_num (i+1, y)%mod*c[y-x][i-x]%MoD; *ans%=MoD; $ }Panax NotoginsengAns+=get_num (x+1, y); -ans%=MoD; theAns+=get_num (x,y-1); +ans%=MoD; Adp[x][y]=ans; the returnDp[x][y]; + } - $ intMain () $ { - Inti (); - while(SCANF ("%d", &n)! =EOF) the { -Memset (DP,0,sizeof(DP));Wuyi for(intI=1; i<=n; i++) the { -scanf"%d",&a[i]); Wu } -printf"%lld\n", Get_num (1, N)); About } $ return 0; -}
View Code
Hdu 5151 sit sit sit