Question: nyoj 1070 weird elevator [I]
This question comes from the OJ 1206 dormitory's elevator of Xiangtan University.
It was the question of the competition at that time. I did not read the question clearly,
Analysis: This is actually a simple one-dimensional DP, using DP [I] to represent the minimum physical strength required from the first layer to the second layer.
Because you cannot stay in the adjacent floor, so you can transfer from DP [I-2], but this is not the best but also from DP [I-3], because so you can reach all the floors. We only need to optimize the DP among all.
One of the other conditions to note is that when transferred from DP [I-3], there are four options for people in the middle of the two layers:
1: go up or go down
2: The upper and lower layers
3: There are two lower layers and two lower layers. (this was not taken into account at the time. Be careful)
The code is easy to write,
AC code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cstdlib> # include <map> # include <cmath> # include <vector> # include <algorithm> using namespace STD; const int n = 100005; int A [n], DP [N]; int main () {int t; scanf ("% d", & T ); for (int cas = 1; CAS <= T; CAS ++) {memset (A, 0, sizeof (a); int num, floor, up, down, X; scanf ("% d", & floor, & num, & up, & down); // opposite for (INT I = 1; I <= num; I ++) {scanf ("% d", & X); A [x] ++;} memset (DP, 0x3f3f3f3f, sizeof (DP); DP [0] = DP [1] = DP [2] = 0; int TMP; int MI = min (Up, down ); for (INT I = 3; I <= floor; I ++) {DP [I] = min (DP [I], DP [I-2] + A [I-1] * mi); If (I-3)> = 1) {TMP = min (A [I-1] * Up + A [I-2] * up * 2, a [I-1] * 2 * down + A [I-2] * down ); TMP = min (TMP, a [I-1] * Up + A [I-2] * down); TMP = min (TMP, A [I-1] * 2 * down + up * 2 * A [I-2]); DP [I] = min (DP [I], DP [I-3] + TMP) ;}} printf ("case % d: % d \ n", Cas, DP [FLOOR]);} return 0 ;}
Nyoj 1070 weird elevator [I] [DP]