【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- poj1062 Bellman 最短路应用
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41066 Accepted: 11959 Descripti ...
- 在Linux终端使用W3M浏览器下载文件
在Linux终端使用W3M浏览器下载文件 W3M 是3个基于Linux系统命令行的WEB网站浏览工具(w3m/Links/Lynx) 对于需要验证cookie 和来源的页面,比如163的超大附件,直接 ...
- Java中二进制字节与十六进制互转
在Java中字节与十六进制的相互转换主要思想有两点: 1.二进制字节转十六进制时,将字节高位与0xF0做"&"操作,然后再左移4位,得到字节高位的十六进制A;将字节低位与0 ...
- Material Design控件使用学习 TabLayout+SwipeRefreshlayout
效果: Tablayout有点类似之前接触过的开源ViewPagerIndicator,将其与viewpager绑定,可实现viewpager的导航功能. SwipeRefreshLayout是官方出 ...
- libsvm 的使用
1. libsvm 支持的SVM模型 官网地址:LIBSVM – A Library for Support Vector Machines libsvm 支持的 SVM 模型如下(C:classif ...
- 分享到twitter,facebook,google,yahoo,linkedined,msn
编辑器加载中... 1. 分享到twitter的代码” title=”分享到 Twitter” target=”_blank” rel=”nofollow”>Twitter 2. 分享到Face ...
- 【Uva 1252】Twenty Questions
[Link]: [Description] 给你n个物体,每个物体都有m种属性; (每个物体的属性都能和别的物体的属性区别) 现在,你已知这n个物体; 然后让一个人心里想一个物体 你可以问这个人,这个 ...
- cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁
1456. [UVa 10881,Piotr's Ants]蚂蚁 ★ 输入文件:Ants.in 输出文件:Ants.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述 ...
- android5.x加入sim1,sim2标识
1,mobile_signal_group.xml ..... <FrameLayout android:id="@+id/mobile_combo" android:la ...
- ActiveReports 9实战教程(2): 准备数据源(设计时、执行时)
在上讲中<ActiveReports 9实战教程(1): 手把手搭建好开发环境Visual Studio 2013 社区版>,我们已经结合Visual Studio 2013搭建好了Act ...