Bridge Automation Gym

题目

  https://cn.vjudge.net/problem/Gym-101490D

题意

  给出n艘船来到的时间,现在他们要过桥,已知大桥抬起放下需要60秒,船只能在完全抬起时经过,需要20s。而一艘船可以最多在桥前等待30分钟,问大桥最少需要保持抬起多久(抬起,放下过程中也算)。

题解

  简单的dp题,然而本蒟蒻也做不出来qwq。对于i船来说有两种可能一种是自己过桥,另外一种是等其他船一起过桥。而一起过桥再分为两种,一种是所有船堆到一起再过,另一种是前面船先过了,保持桥的上升状态再让后面的船过。

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#define ull unsigned long long
#define met(a, b) memset(a, b, sizeof(a))
#define lowbit(x) (x&(-x))
#define MID (l + r) / 2
#define ll long long

using namespace std;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 7;

int arr[maxn];
int dp[maxn];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i];
    for(int i = 1; i <= n; i++) {
        dp[i] = dp[i-1] + 140;//i船自己通过
        for(int j = 1; j < i; j++) {
            //max里分别是让j船先等1780秒通过后保持桥上升状态时 和 将船堆到一起通过。(其实用if else分开也是可以的)
            dp[i] = min(dp[i], dp[j-1] + 120 + max(arr[i] - arr[j]  - 1780, (i - j + 1) * 20));
        }
    }
    cout << dp[n] << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Ruby-Z/p/11383540.html