[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.pswp.cn/news/278725.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278725.shtml
英文地址,請注明出處:http://en.pswp.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…