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即 ...
随机推荐
- 一起了解 .Net Foundation 项目 No.19
.Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. Salesforce To ...
- Linux下MongoDB单实例的安装和配置详解
推荐网站 MongoDB官网:http://www.mongodb.org/ MongoDB学习网站:http://www.runoob.com/mongodb 一.创建MongoDB的资源目录和安装 ...
- svn 追责神器 blame vscode - SVN Gutter
svn 追责神器 blame vscode - SVN Gutter
- foobox,基于foobar2000汉化版的CUI配置整合版
名 称:foobox 作 者:dreamawake 发布博客:https://www.cnblogs.com/foobox/ GitHub: https://github.com/dream7180/ ...
- Lambda表达式学习笔记
Lambda基础语法 Java8中引入了一个新的操作符" -> ",该操作符被称为箭头操作符或Lambda操作符,箭头操作符将Lambda表达式拆分成两部分: 左侧:Lamb ...
- SpringMVC框架——数据绑定
Spring MVC 数据绑定 使用POJO绑定参数 entity package com.sunjian.entity; /** * @author sunjian * @date 2020/3/1 ...
- Selenium系列(五) - 键盘操作详细解读
如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...
- Linux Namespace 入门系列:Namespace API
Linux Namespace 是 Linux 提供的一种内核级别环境隔离的方法.用官方的话来说,Linux Namespace 将全局系统资源封装在一个抽象中,从而使 namespace 内的进程认 ...
- Redis底层函数详解
Redis底层函数详解 serverCron 函数 它负责管理服务器的资源,并维持服务器的正常运行.在执行 serverCron 函数的过程中会调用相关的子函数,如 trackOperationsPe ...
- springboot创建
1.点击File----->New----->Project... 2.输入MAVEN,组名.包名等相关参数 3.选择SpringBoot版本,选择项目需要依赖的相关骨架包 4.设置 ...