当前位置:网站首页>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.
边栏推荐
- 微信公众号调试与Natapp环境搭建
- 60 个神级 VS Code 插件!!
- Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
- Understanding openstack network
- PHP application container deployment practice
- VNC Viewer方式的远程连接树莓派
- Global and Chinese market of music synthesizer 2022-2028: Research Report on technology, participants, trends, market size and share
- [cloud native | kubernetes chapter] Introduction to kubernetes Foundation (III)
- Fastjson 漏洞利用技巧
- Using oasis to develop a hop by hop (I) -- Scene Building
猜你喜欢

Using oasis to develop a hop by hop (I) -- Scene Building

The equipment is connected to the easycvr platform through the national standard gb28181. How to solve the problem of disconnection?

Several common DoS attacks

Recommend several super practical data analysis tools

存在安全隐患 部分冒险家混动版将召回

使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察

实现领域驱动设计 - 使用ABP框架 - 领域逻辑 & 应用逻辑

【面试高频题】难度 3/5,可直接构造的序列 DP 题

MySQL binlog
![clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]](/img/f0/42f394dbc989d381387c7b953d2a39.jpg)
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]
随机推荐
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
Several characteristics of pharmaceutical industry
Paper: Google TPU
Recommend several super practical data analysis tools
Nature刊登量子计算重大进展:有史以来第一个量子集成电路实现
Parameterized tests guide in junit5
Pytorch 转置卷积
一文详解JackSon配置信息
在Gradle 中对Junit5 测试框架引用
Install the imagemagick7.1 library and the imageick extension for PHP
leetcode 139. Word break word split (medium)
Global and Chinese market of training dance clothes 2022-2028: Research Report on technology, participants, trends, market size and share
[download attached] installation and simple use of Chinese version of awvs
C. K-th Not Divisible by n(数学+思维) Codeforces Round #640 (Div. 4)
How to select an open source license
Instruction document for online written examination assistance of smart side school recruitment
Jenkins的便捷式安装
中国产品经理的没落:从怀恋乔布斯开始谈起
Here comes Wi Fi 7. How strong is it?
如何轻松实现在线K歌房,与王心凌合唱《山海》