题意: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)的更多相关文章

  1. E. The Contest ( 简单DP || 思维 + 贪心)

    传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...

  2. 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 ...

  3. 训练报告 (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 ...

  4. [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

    [AtCoder] NIKKEI Programming Contest 2019   本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...

  5. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  6. Helvetic Coding Contest 2019 差A3 C3 D2 X1 X2

    Helvetic Coding Contest 2019 A2 题意:给一个长度为 n 的01序列 y.认为 k 合法当且仅当存在一个长度为 n 的01序列 x,使得 x 异或 x 循环右移 k 位的 ...

  7. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  8. 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 ...

  9. 【AtCoder】Tenka1 Programmer Contest 2019

    Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...

随机推荐

  1. 用Setuptools构建和分发程序包

    目录 使用Setuptools构建和分发软件包 开发人员指南 安装setuptools 基本使用 指定项目的版本 新增和更改的setup()关键字 包括数据文件 参考示例 使用Setuptools构建 ...

  2. codecs打开不同步给编码的文件

    实例: with codecs.open(file=源文件,mode='命令',encoding='编(解)码方式') as 命名:

  3. webstorm 开新项目 setting 设置@目录别名 add @ (languages & Framewors - Javascript - Webpack 4. setting eslint enable

    webstorm 开新项目 setting 设置@目录别名 add @ (languages & Framewors - Javascript - Webpack 4. setting esl ...

  4. iview Checkbox 多选框 单个的时候 如果需要change 以后进行赋值 就要用value 不要用v-modal 然后用updateModel 方法

    noSuchSituationSetFalse () { this.noSuchSituationOne = false this.$refs.noSuchSituationRef.updateMod ...

  5. 公钥体系(PKI)等密码学技术基础

    公钥体系(PKI)等密码学技术基础 公钥体系(Public Key Infrastructure, PKI)的一些概念 对称密码算法, 典型算法:DES, AES 加解密方共用一个密钥 加/解密速度快 ...

  6. 五分钟了解Semaphore

    一.前言 多个线程之间的同步,我们会用到Semaphore,翻译成中文就是信号量.使用Semaphore可以限制多个线程对同一资源的访问.我们先看下C#中对Semaphore的定义,如下图: 翻译成中 ...

  7. Core3.1WebApi_ 同源策略_如何支持跨域(转载)

    原文:https://mp.weixin.qq.com/s/id3fOyGrZI9lLx7PKbVYlg

  8. 【python 数据结构】相同某个字段值的所有数据(整理成数组包字典的形式)

    class MonitoredKeywordMore(APIView): def post(self, request): try: # 设置原生命令并且请求数据 parents_asin = str ...

  9. 【bzoj2049】[Sdoi2008]Cave 洞穴勘测——线段树上bfs求可撤销并查集

    题面 2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 12030 Solved: 6024 Desc ...

  10. linux-manjaro下添加Yahei Hybrid Consola字体

    1.下载地址 http://www.win10zhijia.net/soft/20160921/3217.html 2.解压 unzip xxx 3.安装 sudo mkdir /usr/share/ ...