Bridge Automation Gym - 101490D

题目

  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;
}
复制代码

 

posted @   Ruby·Z  阅读(200)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单
点击右上角即可分享
微信分享提示