首页 > 其他分享 >Codeforces Beta Round 96 (Div. 1) -- C. Logo Turtle (dp,记忆化搜索)

Codeforces Beta Round 96 (Div. 1) -- C. Logo Turtle (dp,记忆化搜索)

时间:2023-04-24 14:14:04浏览次数:35  
标签:Turtle idx -- Codeforces dfs else int ans dir

记忆化搜索

就是暴力,多一步优化,走过的路别走了。说实话,可能是数据水了,居然能过。

const int N = 510;
string s;
int n, ans;
bool st[501][501][2][50];

void dfs(int x, int idx, int dir, int k)
{
	if (st[x][idx][dir][k]) return;
	st[x][idx][dir][k] = 1; //走过的路不走了
	
	if (x == s.size()) 
	{
		if (k % 2 == 0) ans = max(ans, abs(idx));
		else ans = max(ans, abs(abs(idx) - 1));
		return;
	}
	if (s[x] == 'F')
	{
		if (k > 0) dfs(x + 1, idx, dir ^ 1, k - 1);
		if (dir == 0) dfs(x + 1, idx + 1, dir, k);
		else dfs(x + 1, idx - 1, dir, k);
	}
	else 
	{
		if (k > 0) 
		{
			if (dir == 0) dfs(x + 1, idx + 1, dir, k - 1);
			else dfs(x + 1, idx - 1, dir, k - 1);
		}
		dfs(x + 1, idx, dir ^ 1, k);
	}
}
void solve()
{
    cin >> s >> n;
    dfs(0, 0, 0, n);
    cout << ans << '\n';
}

标签:Turtle,idx,--,Codeforces,dfs,else,int,ans,dir
From: https://www.cnblogs.com/NNNZZZ/p/17349312.html

相关文章

  • uiautomatorviewer.bat 多种报错问题的解决办法
    问题一:使用Android_sdk--tools里的uiautomatorviewer.bat定位页面元素时报错:Remoteobjectdoesn'texists解决办法:使用uiautomatorviewer.bat时要关闭Appium。因为它们都使用同一个端口来连接模拟器。 问题二:使用uiautomatorviewer.bat定位页面元素时报错:Unexpected......
  • 河北稳控科技多通道振弦传感器无线采集仪 数据发送详情
    河北稳控科技多通道振弦传感器无线采集仪数据发送详情 每次设备启动后会将采集到的传感器数据进行内部存储,并在设置好的时间间隔将数据发送出去,通过修改“数据发送方式”参数,监测数据可由数据接口输出也可经由无线网络发送。在发送监测数据时,可通过修改“数据包协议”参数来......
  • 视频直播源码,android动画小飞机旋转效果
    视频直播源码,android动画小飞机旋转效果 //小飞机旋转动效果publicclassPlaneViewextendsView{  privatePaintpaint;  privateintwidth;  privateintheight;  privatefloatcurLength;  privatefloatallLength;  privatefloatmAnimato......
  • Vue2入门之超详细教程七-事件处理
    1、简介事件的基本使用:(1)使用v-on:xxx或者@xxx绑定事件,其中xxx是事件名(2)事件的回调需要配置在methods对象中,最终会在vm上(3)methods中配置的函数,不要用箭头函数!否则this就不是vm了(4)methods中配置的函数,都是被Vue所管理的函数,this指向是Vm或......
  • 【JPA】LocalContainerEntityManagerFactoryBean与EntityManger的关系
    @Autowired@Qualifier("primaryEntityManagerFactory")privateEntityManagerprimaryEntityManager;@Primary@Bean(name="primaryEntityManagerFactory")publicLocalContainerEntityManagerFactoryBeanprimaryEntityManagerFactory(Entit......
  • 淘宝app端商品采集接口分享 商品详情图抓取 高并发请求
    接口名称:item_get_app请求方式:POST、GET返回数据格式:json请求示例:#coding:utf-8"""Compatibleforpython2.xandpython3.xrequirement:pipinstallrequests"""from__future__importprint_functionimportrequests#请求示例url默认请求参数已经做URL编......
  • 换币种
    staticvoidMain(string[]args){//只能用一次//IList<HUOWU>hUOWUs=newList<HUOWU>{//newHUOWU(1,1),newHUOWU(2,5),newHUOWU(3,4),//newHUOWU(6,7),newHUOWU(8,12),newHU......
  • javaIO之随机读写
    javaIO包提供了很多可以读写文件的类,但是如果想在文件的指定位置读写,就需要使用RandomAccessFilepublicclassApp{publicstaticvoidmain(String[]args)throwsIOException{{Strings1="ggg\n";Strings2="ggg,hhh\n";......
  • zookeeper下载安装
    1、下载zookeeper官网下载地址:https://zookeeper.apache.org/从国内开源网站下载镜像:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper2、解压如果解压时提示文件已经存在,可能是因为压缩软件不支持解压tar.gz压缩包,可以打开WindowsPowerShell,在执行tar-zxvf.\apache......
  • 森林火灾模拟软件--FlamMap
    FlamMap是一款在64位Windows操作系统环境中运行的火灾分析桌面应用程序。它可以模拟潜在的火灾行为特征(蔓延速度、火焰长度、火线强度等)、在恒定环境条件(天气和燃料水分)下的火灾增长和蔓延以及条件燃烧概率。随着FARSITE的加入,它现在可以在地形、燃料、燃料水分和天气等不......