hdoj4283 You Are the One

題意:每個人出場時獲得等待時間*值的unhappy值。有個棧換出場順序。問怎樣最小?

一開始的時候覺得在中間取斷點,dp[i][j]表示區間全出場后的最小值。那么dp[i][j]=dp[i][k]+dp[k+1][j],但這樣是不行的。因為有可能最優解是[i][k]只出場部分,剩一些在棧里,然后再出場別的。

注意到棧有一個性質,如果第一個元素是第3個出棧,那么在它出棧前第2,3個元素已經出棧了。如果第一個元素第k出棧,那么[2,k]必在前k-1個出棧。那么狀態轉移時就列出所有可能的k。

正:

#pragma comment(linker,"/STACK:1024000000,1024000000") 
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
const int SZ=1e2+20,INF=0x7FFFFFFF;
typedef long long lon;
int n,arr[SZ],sum[SZ],dp[SZ][SZ];void init()
{cin>>n;for(int i=1;i<=n;++i)cin>>arr[i],sum[i]=sum[i-1]+arr[i];for(int len=2;len<=n;++len){for(int i=1;i<=n;++i){int r=i+len-1;if(r>n)break;dp[i][r]=INF;for(int k=1;k<=len;++k){dp[i][r]=min(dp[i][r],dp[i+1][i+k-1]+dp[i+k][r]+(k-1)*arr[i]+(k)*(sum[r]-sum[i+k-1]));//if(i==1&&r==3)cout<<"dp[i][r]: "<<dp[i][r]<<" "<<dp[i+k][r]<<endl;
            }}}
//    for(int i=1;i<=n;++i)
//    {
//        for(int j=i;j<=n;++j)
//        {
//            cout<<"i: "<<i<<"j: "<<j<<" "<<dp[i][j]<<" ";
//        }cout<<endl;
//    }cout<<dp[1][n]<<endl;
}int main()
{std::ios::sync_with_stdio(0);int casenum;cin>>casenum;for(int time=1;time<=casenum;++time){cout<<"Case #"<<time<<": ";init();}return 0;
}

誤:

#pragma comment(linker,"/STACK:1024000000,1024000000") 
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
const int SZ=1e2+20,INF=0x7FFFFFFF;
typedef long long lon;
int n,arr[SZ],sum[SZ],dp[SZ][SZ],st[SZ][SZ];void init()
{cin>>n;for(int i=1;i<=n;++i)cin>>arr[i],sum[i]=sum[i-1]+arr[i];for(int len=2;len<=n;++len){for(int i=1;i<=n;++i){int r=i+len-1;if(r>n)break;st[i][r]=st[i+1][r]+(len-1)*arr[i];}}for(int len=2;len<=n;++len){for(int i=1;i<=n;++i){int r=i+len-1;if(r>n)break;dp[i][r]=st[i][r-1]+(sum[r-1]-sum[i-1]);if(i==1&&r==3)cout<<"h: "<<dp[i][r]<<endl;for(int k=i;k<r;++k){dp[i][r]=min(dp[i][r],dp[i][k]+st[k+1][r-1]+max(0,(k-i+2))*(sum[r-1]-sum[k])+(k-i+1)*arr[r]);if(i==1&&r==3)cout<<"h: "<<dp[i][r]<<endl;}}}
//    for(int i=1;i<=n;++i)
//    {
//        for(int j=i;j<=n;++j)
//        {
//            cout<<"i: "<<i<<"j: "<<j<<" "<<dp[i][j]<<" ";
//        }cout<<endl;
//    }cout<<dp[1][n]<<endl;
}int main()
{std::ios::sync_with_stdio(0);int casenum;cin>>casenum;for(int time=1;time<=casenum;++time){cout<<"Case #"<<time<<": ";init();}return 0;
}

?

轉載于:https://www.cnblogs.com/gaudar/p/9743353.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388316.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388316.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388316.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

laravel-admin 開發 bootstrap-treeview 擴展包

laravel-admin 擴展開發文檔https://laravel-admin.org/doc... 效果圖&#xff1a; 開發過程&#xff1a; 1、先創建Laravel項目&#xff0c;并集成laravel-admin&#xff0c;教程&#xff1a; http://note.youdao.com/notesh... 2、生成開發擴展包 php artisan admin:extend c…

怎么看服務器上jdk安裝位置,查看云服務器jdk安裝路徑

查看云服務器jdk安裝路徑 內容精選換一換用戶可以在公有云MRS集群以外的節點上使用客戶端&#xff0c;在使用客戶端前需要安裝客戶端。如果集群外的節點已安裝客戶端且只需要更新客戶端&#xff0c;請使用安裝客戶端的用戶例如root。針對MRS 3.x之前版本的集群&#xff0c;需要…

公司生日會生日禮物_你的生日有多受歡迎?

公司生日會生日禮物In the years before 2020, it was common for a large number of school children (20–30 or more) to physically colocate for their math lessons. And in many a class, students were asked to compute the probability that two of them had the sam…

Django思維導圖

轉載于:https://www.cnblogs.com/liangying666/p/9744477.html

XebiaLabs DevOps平臺推出軟件發布風險和合規性管理功能

XebiaLabs是DevOps和持續交付軟件工具供應商&#xff0c;通過其DevOps平臺推出了用于軟件版本發布的監管、安全和合規風險評估跟蹤功能。 這些新功能旨在幫助組織跟蹤應用程序的發布狀態信息&#xff0c;了解跨多個應用程序、團隊和環境的安全性和合規性風險。XebiaLabs表示&am…

wp7開發環境搭建

簡介 本文通過step by step的模式講述如何從0開始搭建Window Phone 7開發環境&#xff0c;如果開發簡單的Windows Phone 7程序。只是一篇介紹性的文章,但是邁進Windows Phone 7開發之路其實就那么簡單,一起來開發Windows Phone 7吧。 Windows 7安裝 目前Windows Phone 7開發…

舊金山字體_舊金山建筑業的興衰。 施工趨勢與歷史

舊金山字體This series of articles is devoted to the study of the construction activity of the main city of Silicon Valley — San Francisco. Charts and calculations were built with the help of Jupyter Notebook (Kaggle)該系列文章專門研究硅谷主要城市舊金山的建…

gym100825G. Tray Bien(輪廓線DP)

題意:3 * N的格子 有一些點是壞的 用1X1和1X2的磚鋪有多少種方法 題解:重新學了下輪廓線 寫的很舒服 #include <bits/stdc.h> using namespace std; typedef long long ll;int n, m; int vis[30][5]; ll dp[25][1 << 3];void dfs(int num, int i, int state, int n…

github上打包的樣式為什么在預覽的時候,出現404

這是資源引用的問題 在這里主要是需要在dist的index.html文件內將"./static/css/style.css"改為"static/css/style.css",就可以加載成功了&#xff0c; 至于js的路徑"./static/js/app.js"&#xff0c;就不用改了轉載于:https://www.cnblogs.com/…

lambda函數,函數符_為什么您永遠不應該在Lambda函數中使用print()

lambda函數&#xff0c;函數符兩個Lambda用戶的故事 (A Tale of Two Lambda Users) 故事1&#xff1a;業余 (Tale #1: The Amateur) One moment everything is fine, then … Bam! Your Lambda function raises an exception, you get alerted and everything changes instantl…

[ BZOJ 4668 ] 冷戰

\(\\\) \(Description\) 有\(N\)個點&#xff0c;開始沒有邊相連&#xff0c;進行按順序給出的\(M\)個操作&#xff1a; \(0\ u\ v\) 將\(u,v\)兩點連一條邊\(1\ u\ v\) 查詢\(u,v\)兩點最早在第幾條邊連接的時候被連通每次詢問輸出一個邊的編號&#xff0c;強制在線。 \(N,M\i…

使用容器和數據庫克隆進行數據庫遷移

SQL Server遷移在DBA的生命周期中是一個常量&#xff0c;SQL Server 2008的支持終結正在推動大量的遷移規劃。數據庫遷移通常涉及將備份還原到目標環境&#xff0c;為應用程序測試提供開發和QA環境&#xff0c;以及識別已棄用的功能。當處理涉及需要數小時恢復的大量數據庫的大…

C++獲取PE文件的入口點

2009-10-07 10:17 C獲取PE文件的入口點 源碼&#xff1a; #include "stdafx.h" #include <iostream> #include <windows.h> using namespace std; int main(int argc, char* argv[]) { char *FileName argv[1]; HANDLE hFile CreateFile(FileName,GENE…

ai 中 統計_AI統計(第2部分)

ai 中 統計Today I plan to cover the following topics: Linear independence, special matrices, and matrix decomposition.今天&#xff0c;我計劃涵蓋以下主題&#xff1a;線性獨立性&#xff0c;特殊矩陣和矩陣分解。 線性獨立 (Linear independence) A set of vectors …

如何修改瀏覽器的默認滾動條樣式

如何修改瀏覽器的默認滾動條樣式 /* 瀏覽器滾動條樣式 *//* width */ ::-webkit-scrollbar {width: 4px;height: 4px; }/* Track */ ::-webkit-scrollbar-track {background: rgb(255, 255, 255);border-radius: 8px; }/* Handle */ ::-webkit-scrollbar-thumb {background: rg…

PE

PE文件規定了可執行文件的格式&#xff0c;凡是符合此格式的文件都能在windows系統上運行。PE文件的格式暫且不談&#xff0c;說一些感染PE文件的幾種途徑。 導入表感染。這個涉及比較復雜的操作&#xff0c;首先&#xff0c;要自行寫一個dll文件&#xff0c;提供程序中對原dl…

python入門系列:對象引用、垃圾回收、可變性

Python中的變量是什么 引言 Python和java中的變量本質不一樣&#xff0c;java的變量可以理解為一個盒子&#xff0c;用來容納我們的對象&#xff0c;使用前要先聲明它&#xff0c;好分配給我們合適的內存空間。Python的變量可以理解為一個標簽&#xff0c;先構造出對象&#xf…

twitter數據分析_Twitter上最受歡迎的數據科學文章主題

twitter數據分析If you’ve written data science articles or are trying to get started, finding the most popular topics is a big help in getting your articles read. Below are the steps to easily determine what these topics are using R and the results of the …