Topic Description:
Gives N, which means that the entire sequence is valid by filling (or) the 2*n vacancy. Ask the total number of options.
Analysis:
It's obvious that bare-naked searches are possible, but less efficient.
If we define the state f[i][j], which means the first I vacancy, and J is the number of scenarios for the legal sequence. Then it's very simple, f[i][j]=f[i-1][j-1]+f[i-1][j+1].
Reference program:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=110;
Long long F[MAXN][MAXN];
BOOL A[MAXN];
int n,m;
int main () {
scanf ("%d%d", &n,&m);
memset (A,0,sizeof (a));
for (int i=0;i<m;i++) {
int x;
scanf ("%d", &x);
a[x]=1;
}
F[0][0]=1;
for (int i=1;i<=2*n;i++) (
int j=0;j<=n;j++)
if (A[i]) {if (!j) f[i][j]+=f[i-1][j-1];}
else{
if (j) f[i][j]+=f[i-1][j-1];
if (j<n) f[i][j]+=f[i-1][j+1];
}
printf ("%lld", F[2*n][0]);
return 0;
}
Here a indicates whether this place is limited to fill (.