当前位置:网站首页>C. Three displays codeforces round 485 (Div. 2)
C. Three displays codeforces round 485 (Div. 2)
2022-06-24 16:00:00 【51CTO】
Original link : https://codeforces.com/problemset/problem/987/C

The test sample :
The sample input 1
5
2 4 5 4 10
40 30 20 10 40
Sample output 1
90
The sample input 2
3
100 101 100
2 4 5
Sample output 2
-1
The sample input 3
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Sample output 3
33
Tips :
No violence .
Their thinking : The seniors warned against violence , Or two violent attempts . After the game, I found it was ,dp Just solve it . Okay , Let's talk about ideas , This problem we are asking to solve can make The minimum value of
, among
, So we can discuss one part of it first, that is
, We're going to use dp To solve the , use
Express satisfaction
Of
The minimum value of , We don't care
Value , We just have to find the minimum , meanwhile
Satisfy
Just go . So after we get this minimum, we can get another minimum ? Let's split this comparison into two , So our original three levels of violence for The cycle is broken down into two ,OK, Let's look at the code .
AC Code :
/*
*
*/
//POJ I won't support it
//i Is a cyclic variable ,a For the initial value ,n Is the limit value , Increasing
//i Is a cyclic variable , a For the initial value ,n Is the limit value , Decline .
using
namespace
std;
const
int
inf
=
0x3f3f3f3f;
// infinity
const
int
maxn
=
1e5;
// Maximum .
typedef
long
long
ll;
typedef
long
double
ld;
typedef
pair
<
ll,
ll
>
pll;
typedef
pair
<
int,
int
>
pii;
//******************************* Split line , The above is a custom code template ***************************************//
int
n;
int
a[
maxn],
b[
maxn],
dp[
maxn];
//dp[i] It means a[i]>a[j] bring b[i]+b[j] The minimum value , among 1<=j<i.
int
main(){
//freopen("in.txt", "r", stdin);// When submitting, you should comment out
IOS;
while(
cin
>>
n){
rep(
i,
1,
n)
cin
>>
a[
i];
rep(
i,
1,
n)
cin
>>
b[
i];
memset(
dp,
inf,
sizeof(
dp));
rep(
i,
2,
n){
rep(
j,
1,
i
-
1){
if(
a[
i]
>
a[
j]){
dp[
i]
=
min(
dp[
i],
b[
i]
+
b[
j]);
}
}
}
// We get it again b[i]+dp[j] The minimum value of , This is the answer we want .
int
ans
=
inf;
rep(
i,
2,
n){
rep(
j,
1,
i
-
1){
if(
a[
i]
>
a[
j]){
ans
=
min(
ans,
b[
i]
+
dp[
j]);
}
}
}
if(
ans
==
inf)
cout
<<-
1
<<
endl;
else
cout
<<
ans
<<
endl;
}
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
边栏推荐
- How to easily realize online karaoke room and sing "mountain sea" with Wang Xinling
- Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
- Some experiences of project K several operations in the global template
- 安装ImageMagick7.1库以及php的Imagick扩展
- 存在安全隐患 路虎召回部分混动揽运
- Step by step import RHEL image to Tencent cloud
- Global and Chinese markets of natural insect repellents 2022-2028: Research Report on technology, participants, trends, market size and share
- Remote connection raspberry pie in VNC Viewer Mode
- 如何轻松实现在线K歌房,与王心凌合唱《山海》
- Golang+redis distributed mutex
猜你喜欢

Jenkins 镜像无法更新插件中心的3种解决方法
![Software test [high frequency] interview questions sorted out by staying up late (latest in 2022)](/img/33/2c2256fd98b908ddaf5573f644ad7f.png)
Software test [high frequency] interview questions sorted out by staying up late (latest in 2022)

Apple is no match for the longest selling mobile phone made in China, and has finally brought back the face of the domestic mobile phone

Linux record -4.22 MySQL 5.37 installation (supplementary)

Logging is not as simple as you think

我与“Apifox”的网络情缘
![[cloud native | kubernetes chapter] Introduction to kubernetes Foundation (III)](/img/21/503ed54a2fa14fbfd67f75a55ec286.png)
[cloud native | kubernetes chapter] Introduction to kubernetes Foundation (III)

Solution to the problem that FreeRTOS does not execute new tasks

Understanding openstack network

Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières
随机推荐
【云原生 | Kubernetes篇】Kubernetes基础入门(三)
MySQL binlog
Install the imagemagick7.1 library and the imageick extension for PHP
Istio practical tips: Customize Max_ body_ size
leetcode 139. Word Break 單詞拆分(中等)
My network relationship with "apifox"
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]
How does the effective date of SAP PP ECM affect the work order?
[C language questions -- leetcode 12 questions] take you off and fly into the garbage
Several common DoS attacks
Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières
Apple is no match for the longest selling mobile phone made in China, and has finally brought back the face of the domestic mobile phone
I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
Logging is not as simple as you think
我与“Apifox”的网络情缘
How to implement SQLSERVER database migration in container
几种常见的DoS攻击
[download attached] installation and simple use of Chinese version of awvs
打破内存墙的新利器成行业“热搜”!持久内存让打工人也能玩转海量数据+高维模型
2021-04-27: if the adjacent position of a character does not have the same character