题意就是给你一个若干年后的金字塔,问你当时组成这个样子的情况一共有多少种
进本上是额裸的dp,需要用一下滚动数组。
AC代码:
/* ***********************************************
Author :yzkAccepted
Created Time :2016/4/4 10:37:00
TASK :ggfly.cpp
LANG :C++
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef __int64 ll;
const int maxn=10010;
const ll md=1e9+7;
ll a[maxn];
ll dp[3][maxn];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int j,n,i,tot;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%I64d",&a[i]);
memset(dp,0,sizeof(dp));
if(a[1]>0)
{printf("0\n"); return 0;}
dp[1][0]=1;
tot=1;
for(i=2;i<=n;i++)
{
if(a[i]==-1)
{
for(j=0;j<i&&j+i<=n;j++)
{
if(j==0)
dp[tot^1][j]=(dp[tot][j]+dp[tot][j+1])%md;
else dp[tot^1][j]=(dp[tot][j]+dp[tot][j+1]+dp[tot][j-1])%md;
}
}
else
{
for(j=0;j<i&&j+i<=n;j++)
dp[tot^1][j]=0;
if(a[i]>0)
dp[tot^1][a[i]]=(dp[tot][a[i]]+dp[tot][a[i]-1]+dp[tot][a[i]+1])%md;
else dp[tot^1][a[i]]=(dp[tot][a[i]]+dp[tot][a[i]+1])%md;
}
tot=tot^1;
}
printf("%I64d\n",dp[tot][0]);
return 0;
}