题意略。

思路:

开始的时候,定义dp[i]:当前行在第i行,i~n有多少种排列方式,如果i为f,那么dp[i] = dp[i + 1],因为第i + 1条语句只能放在f后且向右缩进一位;

如果i为s,那么dp[i]还与第i行的缩进有关。因此我们增加缩进这个状态。

定义dp[i][j]:当前行在第i行,缩进为j,i~n有多少种排列方式。

当i为s的时候,dp[i][j] = sum(dp[i + 1][k]) 1 <= k <= j;

当j为f的时候,dp[i][j] = dp[i + 1][j + 1];

详见代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = + ;
const int maxn = ; LL dp[][maxn];
int n;
string str; int main(){
std::ios::sync_with_stdio(false);
cin>>n;
string temp;
for(int i = ;i < n;++i){
cin>>temp;
str += temp;
}
memset(dp,-,sizeof(dp));
for(int i = ;i <= n;++i) dp[n & ][i] = ;
for(int i = n - ;i >= ;--i){
LL cur = ;
for(int j = ;j <= i - ;++j){
if(str[i - ] == 's'){
cur += dp[(i + ) & ][j];
cur %= mod;
dp[i & ][j] = cur;
}
else{
dp[i & ][j] = dp[(i + ) & ][(j + )];
}
}
}
cout<<dp[][]<<endl;
return ;
}

CodeForces 909C的更多相关文章

  1. Codeforces 909C - Python Indentation

    909C - Python Indentation 思路:dp. http://www.cnblogs.com/Leohh/p/8135525.html 可以参考一下这个博客,我的dp是反过来的,这样 ...

  2. Codeforces 909C Python Indentation:树状数组优化dp

    题目链接:http://codeforces.com/contest/909/problem/C 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现. 现在有一种简化版的Pytho ...

  3. Codeforces - 909C - Python Indentation - 简单dp

    http://codeforces.com/problemset/problem/909/C 好像以前做过,但是当时没做出来,看了题解也不太懂. 一开始以为只有上面的for有了循环体,这里的state ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. Selenium浏览器自动化测试框架

    selenium简介 介绍 Selenium [1]  是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 1 ...

  2. js里的Document对象介绍

    activeElement     返回代表文档中dangqianhuodejiaodianyuansudeduixaing body                    返回代表文档中body元素 ...

  3. jumpserver1.4.1 安装过程

    # 修改字符集 localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 export LC_ALL=zh_CN.UTF-8 echo 'LANG="zh_CN. ...

  4. BGP属性控制实验

    目录 实验拓扑 实验需求 实验步骤 个人小结: 实验拓扑 实验需求 更改BGP路由的属性让R4访问R1优先选R2这条路 实验步骤 1. 按照图示配置IP地址及环回口地址 R1 [R1]int g0/0 ...

  5. Shell.Users 提权

    <% Set  o=CreateObject( "Shell.Users" ) Set z=o.create("test") z.changePasswo ...

  6. Java——win10配置环境变量

    一.安装JDK 1.下载jdk                                           地址:https://pan.baidu.com/s/1P9CZZoZ0AzZU0c ...

  7. Redis批量删除key的小技巧,你知道吗?

    在使用redis的过程中,经常会遇到要批量删除某种规则的key,但是redis提供了批量查询一类key的命令keys或scan,没有提供批量删除某种规则key的命令,怎么办?看完本文即可,哈哈. 本文 ...

  8. 认识Linux工具

    Centos7镜像网站:清华,阿里,网易 软件安装:lamp   httpd (认识) yum: 安装工具    需要选版本和特性,所以生产不用yum rpm:安装依赖 源码编译 shell脚本:yu ...

  9. todaytt

    <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.Drawe ...

  10. let 、const 、var、function声明关键字的新理解

    今天在群里看到大佬们讨论let .const 的提升问题,有个大佬问  三种声明都在什么阶段提升?  什么阶段?这个真不清楚,以前是只知道let.const存在死区,没有变量提升,一下子就懵了 后经手 ...