[CF132C] Logo Turtle , Luogu

A turtle moves following by logos.(length is \(N\)) \(F\) means "move 1 unit forward", \(T\) means turned around(180°). You must change the order \(M\) times.(\(F\) -> \(T\) , \(T\) -> \(F\))

\(N \le 50, M \le 100\).

Click here

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
typedef long long LL;
const int INF=1e9+7;
inline LL read(){
register LL x=0,f=1;register char c=getchar();
while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
return f*x;
} const int N = 1005; int dp[N][N][2];
char s[N];
int n, m; inline void chkmax(int& a, int b){ a = a > b ? a : b; } int main(){
// freopen("a.in","r",stdin);
scanf("%s", (s + 1));
n = strlen(s + 1);
m = read(); memset(dp, 0xcf, sizeof dp);
dp[0][0][0] = dp[0][0][1] = 0; for(int i = 1; i <= n; ++i){
for(int j = 0; j <= m; ++j){ // turned j times in total.
for(int k = 0; k <= j; ++k){ // turn k times at i.
if(s[i] == 'F'){
if(k & 1){
chkmax(dp[i][j][0], dp[i - 1][j - k][1]);
chkmax(dp[i][j][1], dp[i - 1][j - k][0]);
}
else{
chkmax(dp[i][j][0], dp[i - 1][j - k][0] + 1);
chkmax(dp[i][j][1], dp[i - 1][j - k][1] - 1);
}
}
if(s[i] == 'T'){
if(k & 1){
chkmax(dp[i][j][0], dp[i - 1][j - k][0] + 1);
chkmax(dp[i][j][1], dp[i - 1][j - k][1] - 1);
}
else{
chkmax(dp[i][j][0], dp[i - 1][j - k][1]);
chkmax(dp[i][j][1], dp[i - 1][j - k][0]);
}
}
}
// printf("dp[%d][%d] = %d, %d\n", i, j, dp[i][j][0], dp[i][j][1]);
}
} printf("%d\n", max(dp[n][m][0], dp[n][m][1]));
}

[CF132C] Logo Turtle的更多相关文章

  1. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP

    题目链接:http://codeforces.com/contest/132/problem/C C. Logo Turtle time limit per test 2 seconds memory ...

  2. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle DP

    C. Logo Turtle   A lot of people associate Logo programming language with turtle graphics. In this c ...

  3. CF#132 C. Logo Turtle DP

    C. Logo Turtle 题意 有一个海龟在一个x轴的0点,给出一个由'F','T'组成的字符序列. 海龟要按照这个序列进行行动,如果第i个字符为'F',表示沿当前方向走,'T'表示转身. 现在你 ...

  4. CodeForces 132C Logo Turtle (记忆化搜索)

    Description A lot of people associate Logo programming language with turtle graphics. In this case t ...

  5. codeforces 132C Logo Turtle(dp)

    可以用三维dp来保存状态, dp[i][j][k]表示在前i个字符变换了j步之后方向为k(k = 1 or k = 0)的最优解,也就是离原点的最大距离.这里规定0方向为正方向,1位负方向,表示的是当 ...

  6. Codeforces Beta Round #96 (Div. 2) E. Logo Turtle dp

    http://codeforces.com/contest/133/problem/E 题目就是给定一段序列,要求那个乌龟要走完整段序列,其中T就是掉头,F就是向前一步,然后开始在原点,起始方向随意, ...

  7. CF习题集二

    CF习题集二 一.CF507E Breaking Good 题目描述 \(Breaking Good\)这个游戏对于有经验的玩家来说也有一定的难度. 游戏的主角小明希望加入一个叫斧头帮的犯罪团伙.这个 ...

  8. Overview over available Turtle and Screen methods

    24.5.2.1. Turtle methods Turtle motion Move and draw forward() | fd() backward() | bk() | back() rig ...

  9. turtle文库 ——python

    本文将会为您介绍关于python--turtle库函数,学会这个库函数,会有很多让你意想不到的事情发生哦! 我也也会为你们,简单的编写几个代码,让你们看一下turtle函数的魅力 Turtle库是Py ...

随机推荐

  1. 【概率论】3-3:累积分布函数(Cumulative Distribution Function)

    title: [概率论]3-3:累积分布函数(Cumulative Distribution Function) categories: Mathematic Probability keywords ...

  2. 第2组 Alpha冲刺(4/4)

    队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:了解整个游戏的流程 GitHub签入记录 接下来的计划:继续完成游戏 还剩下哪些任务:完成游戏 燃尽图 遇到的困难:没有美术比较好的 ...

  3. SDUT2176 -> 递归的函数

    递归的函数                                         Time Limit: 1000 msMemory Limit: 65536 KiB Problem Des ...

  4. 微信小程序之简单记账本开发记录(六)

    昨天虽然将页面成功的搭建出来 但是其中的增删改查功能没有实现,需要到逻辑页面,即js页面注册一下 效果如下图

  5. Python学习日记(五)——初识函数(set、深浅拷贝、三目运算、函数、全局变量和局部变量)

    基本数据类型补充 set set集合,是一个无序且不重复的元素集合 #创建 s = {11,22,33,44}#类似字典 s = set() #转换 l = (11,22,33,44) s1 = se ...

  6. Truffle Smart Contract Error: Invalid number of parameter

      I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-da ...

  7. vagrant box镜像百度下载地址

    1.centos7 链接:https://pan.baidu.com/s/1JuIUo4HL0lm1EtUKaoMpaA提取码:w9a8 2.vagrant-ubuntu-server-16.04-x ...

  8. Centos - php5.4升级到7.1 yum安装

    查看当前 PHP 版本 1 php -v 查看当前 PHP 相关的安装包,删除之 1 2 3 4 5 yum list installed | grep php   yum remove php   ...

  9. Thymeleaf th:include、th:replace引用

    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" ...

  10. ubuntu18 bluebooth

    QDBusPendingReply: type ManagedObjectList is not registered with QtDBus 19:36:14: The program has un ...