【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;
}
【Codeforces Round #455 (Div. 2) C】 Python Indentation的更多相关文章
- 【Codeforces Round #455 (Div. 2) A】Generate Login
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举两个串的前缀长度就好. 组出来. 排序. 取字典序最小的那个. [代码] #include <bits/stdc++.h& ...
- 【Codeforces Round #455 (Div. 2) B】Segments
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出所有的线 其实就是区间. 总共有n*(n+1)/2个 然后按照左端点.右端点排序 每次取最左边的线. 多种可能就取右端点尽量小 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- Linux LVM(逻辑卷管理)
Lvm基本应用 什么是LVM? LVM 的全称是 Logical Volume Manager.中文为逻辑卷管理.它是Linux对磁盘分区的一种管理机制.它在传统的硬盘(或硬盘分区)和文件系统之间建立 ...
- 优化数据页面(20)——1:n的数据关系
设计要点:优化数据页面.界面设计.美化exce 阿金:那一对多的关系-- 秀秀:不是:n结构么? 阿金:嗯,这俺知道.俺特别喜欢这样的格式,那样显得非常上档次! 秀秀:俺也喜欢. 由于页面上有空白,认 ...
- vue7 下拉列表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 存储过程和transaction
https://stackoverflow.com/questions/11531352/how-to-rollback-a-transaction-in-a-stored-procedure BEG ...
- .net framework tools
https://docs.microsoft.com/en-us/dotnet/framework/tools/ Resgen.exe (Resource File Generator) Conver ...
- 自动与因特网时间服务器同步 NTP 服务器 pool.ntp.org, 120.24.166.46 端口 123
自动与因特网时间服务器同步 NTP 服务器 pool.ntp.org 海康提供的NTP服务器 120.24.166.46 端口 123
- Centos7最小化安装后再安装图形界面
1. yum -y groupinstall "X Window System" 2. yum -y groupinstall "GNOME Desktop" ...
- Linux运维管理的必备工具
一.统一账号管理 1.LDAP 统一管理各种平台帐号和密码,包括但不限于各种操作系统(Windows.Linux),Linux系统sudo集成,系统用户分组,主机登入限制等:可与Apache,HTTP ...
- TCP简单说(下)
本文在Creative Commons许可证下发布 TCP的RTT算法 从前面的TCP重传机制我们知道Timeout的设置对于重传非常重要. 设长了,重发就慢,丢了老半天才重发,没有效率,性能差: 设 ...
- Intellij IDEA使用指南(持续更新)(转)
一.项目层面 1.Java开发工具IntelliJ IDEA导入项目 http://jingyan.baidu.com/article/a17d52852118ac8098c8f2c1.html 2. ...