Level Up - ICPC Southeastern Europe Contest 2019(简单DP)


题意:Steve玩魔兽世界要做任务升两级,任务在你不同的等级给的经验不同,输入任务数量和升第一级和升第二级需要的经验,接着输入每个任务第一级完成给的经验和花费的时间、第二级级完成给的经验和花费的时间。求要升两级最少要花多少时间,如果不能则输出-1。
题解:
由题目数据可以直接想到用动态规划来做,因为最多需要的经验只有五百,因此可以开DP[I][J][K](记得开为long long,INF也得更换,我因为这个卡了很久),i代表第一级的经验,J代表第二级的经验,K代表第几个任务。具体见代码注释。
#define _CRT_SECURE_NO_DepRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cctype>
#include <iterator>
#include <vector>
#include <cstring>
#include <cassert>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#define ll long long
#define INF 0x3f3f3f3f
#define ld long double
const ld pi = acos(-.0L), eps = 1e-;
int qx[] = { ,,,- }, qy[] = { ,-,, }, qxx[] = { ,- }, qyy[] = { ,- };
using namespace std;
struct node
{
ll exp1, exp2, time1, time2;//一级的经验 两级的经验 一级消耗的时间 两级消耗的时间
}ren[];
ll dp[][];
bool cmp(node a, node b)
{
return a.exp1 < b.exp1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
ll a, b, c;
cin >> a >> b >> c;
ll ans = ;
for (ll i = ; i <= ; i++)
{
for (ll f = ; f <= ; f++)
{
dp[i][f] = numeric_limits<int64_t>::max();//初始化,注意是longlong!
}
}
for (ll i = ; i < a; i++)
{
cin >> ren[i].exp1 >> ren[i].time1 >> ren[i].exp2 >> ren[i].time2;
}
sort(ren, ren + a, cmp);//先将任务按照第一级经验的大小进行排序,否则易出bug
dp[][] = ;
for (ll i = ; i < a; i++)
{
for (ll f = b; f >= ; f--)
{
for (ll k = c; k >= ; k--)
{
if (dp[f][k] == numeric_limits<int64_t>::max())
{
continue;
}
if (f < b)//如果还没到第二级
{
ll exp1 = f + ren[i].exp1, exp2 = k;
if (exp1 > b)//升级时溢出的经验会保留
{
exp2 = min(c, exp1 - b + k);//避免溢出的经验再溢出
exp1 = b;
}
dp[exp1][exp2] = min(dp[exp1][exp2], dp[f][k] + ren[i].time1);//状态转移
}
ll exp2 = min(k + ren[i].exp2, c);//避免溢出
dp[f][exp2] = min(dp[f][exp2], dp[f][k] + ren[i].time2);//状态转移
}
}
}
if (dp[b][c] == numeric_limits<int64_t>::max())//判断是否有解
{
cout << "-1";
return ;
}
cout << dp[b][c];
return ;
}
Level Up - ICPC Southeastern Europe Contest 2019(简单DP)的更多相关文章
- E. The Contest ( 简单DP || 思维 + 贪心)
传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest
Solved A Gym 100488A Yet Another Goat in the Garden B Gym 100488B Impossible to Guess Solved C Gym ...
- [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)
[AtCoder] NIKKEI Programming Contest 2019 本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...
- [AtCoder] Yahoo Programming Contest 2019
[AtCoder] Yahoo Programming Contest 2019 很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...
- Helvetic Coding Contest 2019 差A3 C3 D2 X1 X2
Helvetic Coding Contest 2019 A2 题意:给一个长度为 n 的01序列 y.认为 k 合法当且仅当存在一个长度为 n 的01序列 x,使得 x 异或 x 循环右移 k 位的 ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- 【AtCoder】Tenka1 Programmer Contest 2019
Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...
随机推荐
- 在Linux上查询物理机信息-不用去拆机器了
目录 一.查看系统信息(包含机器型号) 1.1 查看机型和品牌 二.查看CPU 信息 2.1 查看CPU 型号 2.2 查看CPU的物理数量 2.3 查看 CPU核心数量(非逻辑CPU) 2.4 查看 ...
- 2019-分享数百个 HT 工业互联网 2D 3D 可视化应用案例分享
继<分享数百个 HT 工业互联网 2D 3D 可视化应用案例>2018 篇,图扑软件定义 2018 为国内工业互联网可视化的元年后,2019 年里我们与各行业客户进行了更深度合作,拓展了H ...
- 对Ajax的原理的理解和使用
1.什么是ajax? AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方 ...
- Druid连接池和springJDbc框架-Java(新手)
Druid连接池: Druid 由阿里提供 安装步骤: 导包 durid1.0.9 jar包 定义配置文件 properties文件 名字任意位置也任意 加载文件 获得数据库连接池对象 通过Durid ...
- 推荐三款好用的JSON格式化工具——JSON-handle & HiJson & JSTool
工具一:JSON-handle JSON-Handle是一款谷歌浏览器插件. 1.访问http://jsonhandle.sinaapp.com/下载 2.打开Chrome浏览器的扩展程序(访问chr ...
- SpringBoot2整合Redis多数据源
配置文件属性 spring: redis: database: 1 host: 192.168.50.144 port: 6379 password: timeout: 600 #Springboot ...
- javaweb_HTML
第一章:网页的构成 1.1概念:b/s与c/s 1.1.1 现在的软件开发的整体架构主要分为B/S架构与C/S架构: b/s:浏览器/服务器 c/s:客户端/服务器 客户端:需要安装在系统里,才可使用 ...
- 后端开发使用pycharm的技巧
后端开发使用pycharm的技巧 目录 后端开发使用pycharm的技巧 1.使用说明 2.database 3.HTTP Client 1.使用说明 首先说明,本文所使用的功能为pycharm专业版 ...
- RTSP协议进行视频取流的方法、注意点及python实现
在视频应用中,我们一般都需要基于摄像头或录像机的视频流进行二次开发,那么就涉及到如何将视频流取出来. 在摄像机安装好之后,一般是通过局域网与本地的服务器进行连接,要取录像机的视频流就要在局域网范围内进 ...
- jmeter3.3 接口压测入门和软件下载
Jmeter3.3软件下载地址 https://download.csdn.net/download/qq_36625806/11076556 简单的使用教程 1.启动Jmeter 双击jemeter ...