当前位置:网站首页>C. Mortal Kombat Tower(cf)dp
C. Mortal Kombat Tower(cf)dp
2022-06-11 14:06:00 【Xuanji, you have no heart】
Original link :Problem - 1418C - Codeforces
The main idea of the topic : There's a sequence n Number , Not 0 namely 1, There are two people , One is your friend , One is you . From left to right , Start with your friends , Everyone must choose one or two numbers at a time .ta After you choose, you choose again ta choose ... Ask your friend the minimum value of the last number .
1. In fact, let your friends get less 1, Get more 0;
2. use 0 Show your friend ,1 Show yourself . State shift : use dp[i][0] Indicates the number of hits i Strange , And your friend finished it .dp[i][1] Indicates the number of hits i Strange , And you finished it .
2. State transition equation :
// If a friend takes this number , Just take a[i - 1] It was the last thing I took plus a[i] and a[i - 2] It was the last thing I took plus ..
dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i - 1] + a[i]); // The first number a friend takes, the second of the two numbers
dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);
AC Code :
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;
const double pi = acos(-1.0);
#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(i, n) for (int i = n; i >= (1); --i)
typedef long long ll;
#define sqar(x) ((x)*(x))
const int N = 2e5 + 10;
int dp[N][2]; // The first i When they are closed, they are taken by friends a[i] This value is also the minimum value of my friend when I take this value 0: friend 1 : I
int a[N];
int main(){
int n,t;
cin >> t;
while(t--){
cin >> n;
rep(i, n) cin >> a[i];
dp[1][0] = a[1]; dp[1][1] = INF; // initialization
dp[2][0] = a[1] + a[2]; dp[2][1] = a[1]; //dp[i][0]、dp[i][1] Are the minimum values of friends , therefore dp[2][1] yes a[1] instead of a[2]
for(int i =3; i <= n; i++){
dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i - 1] + a[i]); // Last time I chose one or two
dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);
}
cout << min(dp[n][0], dp[n][1]) << endl;
}
return 0;
}边栏推荐
- NoSQL之Redis配置与优化
- cadence SPB17.4 - allegro - allegro_ free_ viewer
- Part 23, two-way circular linked list model.
- Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
- [201] PHP exception handling - try catch finally exception handling in PHP
- Can't understand kotlin source code? Starting with the contracts function~
- Leetcode 1962. 移除石子使总数最小(应该是向上取整)
- Application choreography nomad vs. kubernetes
- Distributed file system and enterprise application -- elk enterprise log analysis system
- d区间到可空转换
猜你喜欢

Work summary: it took a long time to write SQL because of Cartesian product problem (Cartesian product summary attached)
![[issue 268] accidentally submit the test code to the production environment. I will teach you six ways to solve it in seconds!](/img/e7/448ba3e38fe8c14301f4dfef7f0346.jpg)
[issue 268] accidentally submit the test code to the production environment. I will teach you six ways to solve it in seconds!

Code comparison tool, I use these six

阿里一面,谈谈策略模式在项目中的使用

【公开课预告】:MXPlayer OTT音视频转码实践和优化

cadence SPB17.4 - group operation(add to group, view group list, delete group)

Introduction to long connection

airtest自动化测试

Using vscode code code template to improve mobx coding efficiency

No delay / no delay live video instance effect cases
随机推荐
vim二次替换
CVPR 2022 | neural radiation field geometry editing method nerf editing
为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
Kubernetes binary installation (v1.20.16) (V) verifying master deployment
How to learn to spend money
LNMP deployment
.NET C#基础(6):命名空间 - 有名字的作用域
d区间到可空转换
2022.2.28 variable length sequence table
Redis uses 10 tips, please accept!
XXVIII - 3D point cloud real-time and offline generation of 2D grid and 3D grid map
sqlmap检测SQL-lab靶场
JSP implementation of performance appraisal system for bank counter business
Checkout design in SAP Spartacus
My struggle: my years in foreign enterprises (II)
基于Qt开发实现的任务管理器
2022年全国最新消防设施操作员(初级消防设施操作员)题库及答案
Easyexcel configuration and Application
SQL:如何用采购单销售单的数据 通过移动加权平均法 计算商品成本
2022.2.26 library management system 2 - module 2: reader management system