Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2861
Test instructions: N bench have m personal sit, ask just to divide the sequence into K section way.
Analysis:
A[N][M][K]=A[N-1][M][K]+B[N-1][M][K-1];
B[N][M][K]=A[N-1][M-1][K-1]+B[N-1][M-1][K];
A[n][m][k]: Indicates that there are n seats, m individuals, divided into K-segment, the last position of no one's situation;
B[n][m][k]: Indicates the number of people with n seats, m individuals, divided into k segments, last position.
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<stack>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 100010#defineCLR (a) (Memset (A,0,sizeof (a)))using namespacestd; LL a[205][205][ +],b[205][205][ +];voidinit () { for(intI=1; i<= $; i++) a[i][0][1]=1; b[1][1][1]=1; for(intI=2; i<= $; i++) { for(intj=1; j<=i;j++) { for(intk=1; k<=i&&k<= -; k++) {A[i][j][k]=a[i-1][j][k]+b[i-1][j][k-1]; B[I][J][K]=a[i-1][j-1][k-1]+b[i-1][j-1][k]; } } }}intMain () {intN,m,k;init (); while(SCANF ("%d%d%d", &n,&m,&k) >0) {printf ("%i64d\n", a[n][m][k]+B[n][m][k]); }}View Code
hdu2861 (Recursive)