Div3 595 E
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Div3 595 E相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/elevator' title='elevator'>elevator span cin mem 浜岀淮 ems ble tor return
绠€鍗曠殑浜岀淮DP
$f[i][j] $ 琛ㄧず绗?(i-1) 灞備娇鐢?绗?span class="math inline">(j) 绉嶆柟娉曡揪鍒?绗?(i) 鎵€闇€瑕佺殑鏈€鐭椂闂达紝(j = 0) 浠h〃 璧版ゼ姊紝(j = 1) 鐢垫銆?/p>
(f[i+1][0]) 琛ㄧず绗?(i) 灞備娇鐢?妤兼 鍒拌揪 绗?span class="math inline">(i+1) 灞傜殑鏈€鐭椂闂?/p>
鍙湁褰撶(i) 灞傝蛋妤兼锛岀 (i+1) 灞傝蛋鐢垫鐨勬椂鍊欙紝鎵嶇敤鍔犱笂 (c) 瀹冩槸绛夊緟鐢垫鐨勬椂鍊欙紝
濡傛灉 绗?(i) 灞傚凡缁忓湪鐢垫閲岄潰锛岀(i+1) 涓嶇敤绛夌數姊氨鍙互涓婂幓浜嗭紝鎵€浠ヤ笉鐢ㄥ姞 (c)
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n,c;
int a[N],b[N],f[N][2]; // f1,0 涓嶅湪鐢垫锛宖1,1 鍦ㄧ數姊唴
int main(){
bool ok = 1;
cin >> n >> c;
for(int i = 1;i < n; ++i) cin >> a[i];
for(int i = 1;i < n; ++i) cin >> b[i];
memset(f,0x3f,sizeof f);
f[1][0] = 0,f[1][1] = c;
for(int i = 1;i < n; ++i){
f[i+1][0] = min(f[i+1][0],f[i][1] + a[i]);
f[i+1][0] = min(f[i+1][0],f[i][0] + a[i]);
f[i+1][1] = min(f[i+1][1],f[i][1] + b[i]);
f[i+1][1] = min(f[i+1][1],f[i][0] + b[i] + c);
}
for(int i = 1;i <= n; ++i) cout << min(f[i][0],f[i][1]) <<" ";
return 0;
}
以上是关于Div3 595 E的主要内容,如果未能解决你的问题,请参考以下文章
E. By Elevator or Stairs?.Codeforces Round #595 (Div. 3)
题解Codeforces Round #595 (Div. 3)(CF1249)