【Codeforces Round #455 (Div. 2) C】 Python Indentation
Python Codeforces div round
2023-09-14 09:03:45 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
一个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;
}
相关文章
- python的安装教程_Python的安装
- 如何使用python读取txt文件中的数据
- Python入门系列(十一)一篇搞定python操作MySQL数据库
- python中dtype什么意思_NumPy Python中的数据类型对象(dtype)
- 符合python命名规范的标识符是什么_Python标识符命名规范
- 日拱一卒,伯克利牛叉,这是我见过最酷炫的Python作业
- Python学习:定义函数的默认参数和可变参数
- Python获取图像大小_如何读取0像素图片
- Python将数据写入txt文件_python将内容写入txt文件
- Python 操作XML文件一文通
- Python 异步: 什么是事件循环 ?(6)
- python-Python与PostgreSQL数据库-处理PostgreSQL查询结果
- Python函数——学习笔记详解编程语言
- Linux上的Python之旅(linux自带python)
- Python for循环读取文件
- Python简易操作MySQL入门教程(python操作mysql)
- Linux查看Python安装路径的方法(linux查看python安装路径)
- Linux环境下Python开发的历程(linux与python)
- Python实现MySQL数据库的读取(python读取mysql)
- Python内置的字符串处理函数详细整理(覆盖日常所用)
- 跟老齐学Python之??碌某??/h1>