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即 ...
随机推荐
- 【ERROR 1064 (42000)】MySQL中使用mysqladmin或set修改root密码时提示语法错误
报错信息: mysql> mysqladmin -uroot -p123456 password 654321; ERROR 1064 (42000): You have an error in ...
- Windows下EDK2环境的搭建以及经典的程序设计Print Hello World !-----(Linux下的待后续熟练了再更新)
很久没有更新博客了,之前的博客末尾有提到过要写有关EDK2环境搭建的博客,现在就是完成的时候了,后续博客更新会比较规律(大概每周一篇?) 本人博客仅仅发表于博客园,本人主页为 http ...
- Array.isArray() 判断是不是数组
var arr = new Array(); if(Array.isArray()){ console.log('yes') } else { conssole.log('no') }
- Python基础篇(四)_组合数据类型的基本概念
Python基础篇——组合数据类型的基本概念 集合类型:元素的集合,元素之间无序 序列类型:是一个元素向量,元素之间存在先后关系,通过序号进行访问,没有排他性,具体包括字符串类型.元组类型.列表类型 ...
- 【问题记录】记一次ConnectionTimeout问题排查
最近做性能测试时,发现连接第三方系统时会有约1%的交易提示如下错误 nested exception is org.apache.commons.httpclient.ConnectTimeoutEx ...
- pycharm 更换pip镜像源为国内,解决下载慢的问题
参考链接:https://www.cnblogs.com/hkgov/p/7799078.html 官方源下载速度太慢,换成国内源会很快. 推荐清华的源:https://pypi.tuna.tsing ...
- 解析源码,彻底弄懂HashMap(持续更新中)
为啥突然想着看HashMap源码了? 无意间看到有人说HashMap能考验Java程序员的基本功,之前我作为面试官帮公司招人的时候偶尔问起HashMap,大部分人回答基本都会用,且多数仅停留在put, ...
- Thinkphp绕过宝塔getshell
可以看到直接被拦了,经测试这里是敏感函数字符拦截,大部分有用的敏感函数都被拦了,这里面被拦的是phpinfo() Emmmm,怎么办呢..... 直接执行代码不行,那么就写入代码吧,用file_put ...
- Linux你不知道的ping操作
1.指定ping的次数 -c 选项 ping -c 3 www.baidu.com 2.只返回结果 -q 选项 ping -q -c 3 www.baidu.com 3.指定数据包的大小 -s ...
- nginx 自动化定时切割日志
NG在默认情况下,是始终输出到一个日志文件中,日志文件在nginx.conf中 : access_log logs/www.access.log main; 一个文件中不是很方便查找,分析数据, ...