您的位置:首页 > 其它

cf 495人题 简单dp

2018-01-19 00:06 411 查看
就是python的语法,for之后一定要缩进,给出for或者statement的顺序,问你代码形式有多少种.

/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define lson lmrt<<1
#define rson m+1rrt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define gcd __gcd
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MAXM = 5e3+17;

const int MOD = 1e9+7;
const int MAXN = 5e3+17;
int dp[MAXN][MAXN];
char cmd[MAXN];
int main(int argc ,char const *argv[])
{
#ifdef GoodbyeMonkeyKing
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int n;
cin>>n;
for (int i = 0; i < n; ++i)
cin>>cmd[i];
dp[0][0] = 1;
for (int i = 1; i < n; ++i)
{
if(cmd[i-1]=='f')
for (int j = 0; j < n; ++j)
dp[i][j+1] = dp[i-1][j];
else
{
int sum = 0;
for (int j = n-1; j > -1; --j)
{
dp[i][j] = (sum+dp[i-1][j])%MOD;
sum=(dp[i-1][j]+sum)%MOD;
}
}
}
int ans = 0;
for (int i = 0; i <= n; ++i)
ans=(dp[n-1][i]+ans)%MOD;
cout<<ans<<endl;
return 0;
}


期末血炸,心态崩了,希望可以好好做题.做一个废物真的好痛苦啊
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: