#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#include<memory.h>
#include<cstring>
#include <deque>
using namespace std;
typedef long long ll;
const int N = 22;
int n;
ll d[N][N];
bool vis[N][N];
char str[N];
ll dp(int i,int j){
if(vis[i][j]) return d[i][j];
vis[i][j]=true;
if(i == n) return d[i][j]=(j==0);
ll ans = 0;
if(str[i] =='+'){
if(j) ans+=j*dp(i+1,j);
ans+=dp(i+1,j+1);
}
else {
if(j) ans+=j*j*dp(i+1,j-1)+j*dp(i+1,j);
}
return d[i][j]=ans;
}
int main()
{
while(scanf("%s",str)==1){
memset(vis,false,sizeof(vis));
n=strlen(str);
printf("%I64d\n",dp(0,0));
}
return 0;
}
tjut 4689
最新推荐文章于 2016-11-04 22:02:44 发布