【Codeforces Round #455 (Div. 2) C】 Python Indentation

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

一个for循环之后。 下一个写代码的地方一是从(x+1,y+1)开始的

然后如果写完了一个simple statement
下次就有(x+1,y),(x+1,y-1),(x+1,y-2)..(x+1,0)这些位置可以写下一行的代码了。

写个记忆化搜索就好。
(这里的y就是tab的个数-1)

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 5000;
const ll MOD = 1e9+7;

int n;
char s[5];
vector <char> v;
ll f[N+10][N+10];

ll dfs(int x,int y){
    if (x==n) return 1;
    if (f[x][y]!=-1) return f[x][y];
    ll &ans = f[x][y];
    ans = 0;
    if (v[x]=='f'){
        ans =(ans+ dfs(x+1,y+1))%MOD;
    }else{
        ans =(ans+dfs(x+1,y))%MOD;
        if (y>=2) {
            ans =(ans+dfs(x,y-1))%MOD;
        }
    }
    return ans;
}

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);
	memset(f,255,sizeof f);
	v.push_back('*');
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> s;
        v.push_back(s[0]);
    }
    cout << dfs(1,1) << endl;
	return 0;
}

posted @ 2017-12-28 10:06  AWCXV  阅读(355)  评论(2编辑  收藏  举报