题目描述:
给出n,表示在2*n个空位上填(或),使得整个序列是合法的。问总共有多少种方案。
分析:
显然裸裸的搜索是可以的,但是效率比较低。
如果我们定义状态f[i][j],表示前i个空位,还需j个)就是合法序列的方案数。那么就很简单了,f[i][j]=f[i-1][j-1]+f[i-1][j+1]。
参考程序:
#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("