Nyoj 1070 weird elevator [I] [DP]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.