909C - Python Indentation

思路:dp。

http://www.cnblogs.com/Leohh/p/8135525.html

可以参考一下这个博客,我的dp是反过来的,这样就可以边转移边求前缀和,不需要用树状数组优化。

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a)) const int N=5e3+;
const int MOD=1e9+;
int dp[N][N];
char c[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin>>n;
for(int i=;i<=n;i++)cin>>c[i];
for(int i=;i<n;i++)dp[n][i]=;
for(int i=n-;i>=;i--)
{
int sum=;
for(int j=;j<n;j++)
{
sum=(sum+dp[i+][j])%MOD;
if(c[i]=='f')dp[i][j]=(dp[i][j]+dp[i+][j+])%MOD;
else dp[i][j]=(dp[i][j]+sum)%MOD;
}
}
cout<<dp[][]<<endl;
return ;
}

Codeforces 909C - Python Indentation的更多相关文章

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

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

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

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

  3. Codeforces 909 C. Python Indentation (DP+树状数组优化)

    题目链接:Python Indentation 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现.现在有一种简化版的Python,只有两种语句: (1)'s'语句:Simple ...

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

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...

  5. Python Indentation

    In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of th ...

  6. Codeforces909C Python Indentation(动态规划)

    http://codeforces.com/problemset/problem/909/C dp[i][j]表示第i行缩进j的方案数. 当第i-1行为f时,无论当前行是f或s都必须缩进,即dp[i] ...

  7. CodeForces 909C

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

  8. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...

  9. CodeForces - 798D Mike and distribution 想法题,数学证明

    题意:给你两个数列a,b,你要输出k个下标,使得这些下标对应的a的和大于整个a数列的和的1/2.同时这些下标对应的b //题解:首先将条件换一种说法,就是要取floor(n/2)+1个数使得这些数大于 ...

随机推荐

  1. 问题排查之'org.apache.rocketmq.spring.starter.core.RocketMQTemplate' that could not be found.- Bean method 'rocketMQTemplate' in 'RocketMQAutoConfiguration' not loaded.

    背景 今天将一个SpringBoot项目的配置参数从原有的.yml文件迁移到Apollo后,启动报错“Bean method 'rocketMQTemplate' in 'RocketMQAutoCo ...

  2. C# 将字节流转换为图片的实例方法(转)

    代码如下: usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem. ...

  3. python 用类方法和静态方法实现是追加写文件内容,和读指定行号的内容

    用类方法和静态方法实现:一个是追加写文件一行内容,一个是读指定行号的内容   #coding=utf-8   class handle_file(object):     def __init__(s ...

  4. Linux基础命令---ckconfig

    chkconfig 启动或者关闭系统服务,设置服务的运行级别,该指令并不会立刻启动或者停止服务,而是在开机的时候发生效果. chkconfig提供了一个简单的命令行工具,用于维护/etc/rc[0-6 ...

  5. SpringBoot之RESTFul风格的接口调用(jQuery-Ajax)

    一.Get $.ajax({ type: "get", url: "url地址", async: true, dataType:"json" ...

  6. apache中的https设置基于阿里云免费ssl服务

    环境是:debian7+apache2.2+阿里云免费ssl服务,站点以前的http已经在运行了, 1.开通阿里云免费SSL&DNS解析配置 购买位置:打开阿里云找到“产品”-“安全”-“CA ...

  7. python的re正则表达式模块

    元字符  .   *   +   ?   ^   $   { }     [ ]     -     \ .  匹配除了/n之外的任意一个字符 * 匹配*前面的单个字符任意次,即[0,+∞] + 匹配 ...

  8. Ubuntu下使用face_recognition进行人脸识别

    Face Recognition是一个基于Python的人脸识别库,在github上地址如下:https://github.com/ageitgey/face_recognition. 看着挺好玩,本 ...

  9. C++微专业课程辅导(内存模型和动态内存)

    “除了静态内存和栈内存之外,每个程序还拥有一个内存池.这部分空间被称作自由空间(free store)或堆(heap).程序用堆来存储动态分配(dynamically allocate)的对象”——& ...

  10. zabbix配置自动发现,故障邮件告警

    对网段内的主机进行自动发现,自动加入主机组,自定加入template 创建动作时,类型这里选择discovery 然后将发现的主机加入host group和template: 动作针对的是discov ...