[USACO10DEC] Treasure Chest

题目链接

90 Points:智障的区间 DP……设 dp[i][j] 表示区间 [i, j] 能取的最大价值,但我还是 sd 地开了第三维表示先取还是后取的价值。

交上去以为能 A,结果 #2 开心地 MLE……一看内存,64MB(把评测机吊起来打一顿)……

100 Points:有些神仙……区间 DP 的滚动数组,dp[i] 表示以 i 为首的区间得到的最大价值。

换一种思路,定义 dp[l][r] 为在区间 [l,r] 先手的人能取到的最大值,区间的长度每加 1,先手就会互换一次,为了让这一次的先手更大,就要让上一次更小,于是得到:

$ dp[l][r] = sum[r] - sum[l - 1] - min(dp[l][r - 1], dp[l + 1][r]); $

斜着滚掉一维……dp[i] 为从 i 到 i + l - 2 区间最优解:

$ dp[i] = sum[j] - sum[i - 1] - min(dp[i], dp[i + 1]); $

放上代码。

90 分:

#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;const int maxn = 5000 + 10;
int n, c[maxn], dp[maxn][maxn][2];int main(int argc, const char *argv[])
{freopen("..\\nanjolno.in", "r", stdin);freopen("..\\nanjolno.out", "w", stdout);scanf("%d", &n);for(int i = 1; i <= n; ++i) scanf("%d", &c[i]), dp[i][i][0] = c[i];for(int i = 1; i < n; ++i)dp[i][i + 1][0] = max(c[i], c[i + 1]), dp[i][i + 1][1] = min(c[i], c[i + 1]);for(int i = 3; i <= n; ++i) {for(int l = 1; l <= n - i + 1; ++l) {int r = l + i - 1;if( c[l] + dp[l + 1][r][1] > c[r] + dp[l][r - 1][1] )dp[l][r][0] = c[l] + dp[l + 1][r][1], dp[l][r][1] = dp[l + 1][r][0];else dp[l][r][0] = c[r] + dp[l][r - 1][1], dp[l][r][1] = dp[l][r - 1][0];}}printf("%d %d\n", dp[1][n][0], dp[1][n][1]);fclose(stdin), fclose(stdout);return 0;
}

100 分:

#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;const int maxn = 5000 + 10;
int n, c[maxn], dp[maxn];int main(int argc, const char *argv[])
{freopen("..\\nanjolno.in", "r", stdin);freopen("..\\nanjolno.out", "w", stdout);scanf("%d", &n);for(int i = 1; i <= n; ++i) scanf("%d", &dp[i]), c[i] = c[i - 1] + dp[i];for(int i = 2; i <= n; ++i) {for(int l = 1; l <= n - i + 1; ++l) {int r = l + i - 1;dp[l] = c[r] - c[l - 1] - min(dp[l], dp[l + 1]);}}printf("%d\n", dp[1]);fclose(stdin), fclose(stdout);return 0;
}

 —— 月光 委身依赖

    红莲 彻骨清明

    残留余韵 是抗争 徒留其名

转载于:https://www.cnblogs.com/nanjoqin/p/10090619.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278725.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

工程化,模块化,组件化,规范化

前端讲究 工程化&#xff0c;模块化&#xff0c;组件化&#xff0c;层层递进。 一、工程化 工程化是整个工程的结构、样式和动作分离&#xff0c;工程化是一种思想而不是某种技术&#xff08;当然为了实现工程化我们会用一些技术&#xff09;。各种规范、技术选型、项目构建优…

linux压缩和解压缩_Linux QuickTip:一步下载和解压缩

linux压缩和解压缩Most of the time, when I download something it’s a file archive of some kind – usually a tarball or a zip file. This could be some source code for an app that isn’t included in Gentoo’s Portage tree, some documentation for an internal …

Spark架构与作业执行流程简介

2019独角兽企业重金招聘Python工程师标准>>> Spark架构与作业执行流程简介 博客分类&#xff1a; spark Local模式 运行Spark最简单的方法是通过Local模式&#xff08;即伪分布式模式&#xff09;。 运行命令为&#xff1a;./bin/run-example org.apache.spark.exam…

Spring boot整合Mongodb

最近的项目用了Mongodb&#xff0c;网上的用法大多都是七零八落的没有一个统一性&#xff0c;自己大概整理了下&#xff0c;项目中的相关配置就不叙述了&#xff0c;由于spring boot的快捷开发方式&#xff0c;所以spring boot项目中要使用Mongodb&#xff0c;只需要添加依赖和…

nodejs和Vue和Idea

文章目录Vue环境搭建Idea安装Idea中配置Vue环境Node.js介绍npm介绍Vue.js介绍[^3]Idea介绍Vue环境搭建 概述&#xff1a;vue环境搭建&#xff1a;需要npm&#xff08;cnpm&#xff09;&#xff0c;而npm内嵌于Node.js&#xff0c;所以需要下载Node.js。 下载Node.js&#xff1…

Spring MVC上下文父子容器

2019独角兽企业重金招聘Python工程师标准>>> Spring MVC上下文父子容器 博客分类&#xff1a; java spring 在Spring MVC的启动依赖Spring框架&#xff0c;有时候我们在启动Spring MVC环境的时候&#xff0c;如果配置不当的话会造成一些不可预知的结果。下面主要介绍…

12.7 Test

目录 2018.12.7 TestA 序列sequence(迭代加深搜索)B 轰炸bomb(Tarjan DP)C 字符串string(AC自动机 状压DP)考试代码AC2018.12.7 Test题目为2018.1.4雅礼集训。 时间&#xff1a;4.5h期望得分&#xff1a;010010实际得分&#xff1a;010010 A 序列sequence(迭代加深搜索) 显然可…

word文档中统计总页数_如何在Google文档中查找页数和字数统计

word文档中统计总页数Whether you’ve been given an assignment with a strict limit or you just like knowing how many words you’ve written, Google Docs has your back. Here’s how to see exactly how many words or pages you’ve typed in your document. 无论您是…

vue 入门notes

文章目录vue一、js基础二、封装缓存三、组件1、组件创建、引入、挂载、使用2、组件间的传值- 父组件主动获取子组件的数据和方法&#xff08;子组件给父组件传值&#xff09;&#xff1a;- 子组件主动获取父组件的数据和方法&#xff08;父组件给子组件传值&#xff09;&#x…

spring集成 JedisCluster 连接 redis3.0 集群

2019独角兽企业重金招聘Python工程师标准>>> spring集成 JedisCluster 连接 redis3.0 集群 博客分类&#xff1a; 缓存 spring 客户端采用最新的jedis 2.7 1. maven依赖&#xff1a; <dependency> <groupId>redis.clients</groupId> <artifact…

html-盒子模型及pading和margin相关

margin: <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Title</title><style>* {margin: 0;padding: 0;}/*margin 外边距 元素与其他元素的距离&#xff08;边框以外的距离&#xff09;一…

火狐浏览器复制网页文字_从Firefox中的网页链接的多种“复制”格式中选择

火狐浏览器复制网页文字Tired of having to copy, paste, and then format links for use in your blogs, e-mails, or documents? Then see how easy it is to choose a click-and-go format that will save you a lot of time and effort with the CoLT extension for Firef…

vscode配置、使用git

文章目录一、下载、配置git二、vscode配置并使用git三、记住密码一、下载、配置git 1、git-win-x64点击下载后安装直接安装&#xff08;建议复制链接用迅雷等下载器下载&#xff0c;浏览器太慢&#xff0c;记住安装位置&#xff09;。 2、配置git环境变量&#xff1a; 右键 此…

BTrace功能

2019独角兽企业重金招聘Python工程师标准>>> BTrace功能 一、背景 在生产环境中可能经常遇到各种问题&#xff0c;定位问题需要获取程序运行时的数据信息&#xff0c;如方法参数、返回值、全局变量、堆栈信息等。为了获取这些数据信息&#xff0c;我们可以…

.NET(c#) 移动APP开发平台 - Smobiler(1)

原文&#xff1a;https://www.cnblogs.com/oudi/p/8288617.html 如果说基于.net的移动开发平台&#xff0c;目前比较流行的可能是xamarin了&#xff0c;不过除了这个&#xff0c;还有一个比xamarin更好用的国内的.net移动开发平台&#xff0c;smobiler&#xff0c;不用学习另外…

如何在Vizio电视上禁用运动平滑

Vizio维齐奥New Vizio TVs use motion smoothing to make the content you watch appear smoother. This looks good for some content, like sports, but can ruin the feel of movies and TV shows. 新的Vizio电视使用运动平滑来使您观看的内容显得更平滑。 这对于某些内容(例…

无服务器架构 - 从使用场景分析其6大特性

2019独角兽企业重金招聘Python工程师标准>>> 无服务器架构 - 从使用场景分析其6大特性 博客分类&#xff1a; 架构 首先我应该提到&#xff0c;“无服务器”技术肯定有服务器涉及。 我只是使用这个术语来描述这种方法和技术&#xff0c;它将任务处理和调度抽象为与…

ES6实用方法Object.assign、defineProperty、Symbol

文章目录1.合并对象 - Object.assign()介绍进阶注意用途2.定义对象 - Object.defineProperty(obj, prop, descriptor)3.新数据类型- Symbol定义应用1.合并对象 - Object.assign() 介绍 assign方法可以将多个对象&#xff08;字典&#xff09;&#xff0c;语法&#xff1a;Obj…

Enable Authentication on MongoDB

1、Connect to the server using the mongo shell mongo mongodb://localhost:270172、Create the user administrator Change to the admin database: use admindb.createUser({user: "Admin",pwd: "Admin123",roles: [ { role: "userAdminAnyDataba…

windows驱动程序编写_如何在Windows中回滚驱动程序

windows驱动程序编写Updating a driver on your PC doesn’t always work out well. Sometimes, they introduce bugs or simply don’t run as well as the version they replaced. Luckily, Windows makes it easy to roll back to a previous driver in Windows 10. Here’s…