HackerRank "Dorsey Thief"
A variation to 0-1 Knapsack. (No Python code got fully AC. Python is too slow for this problem)
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int main()
{
// Get input
int N, X; cin >> N >> X;
vector<int> weight, cost;
for (int i = ; i < N; i++)
{
int w, c; cin >> w >> c;
weight.push_back(w);
cost.push_back(c);
} // T
typedef pair<long long, int> Rec; // max-profit, cost
vector<Rec> f(X + );
for (int i = ; i < N; i++)
for (int v = X; v >= cost[i]; v--)
{
int newCost = f[v - cost[i]].second + cost[i];
long long newProf = f[v - cost[i]].first + weight[i];
if (newCost == v)
{
f[v].first = max(f[v].first, f[v - cost[i]].first + weight[i]);
f[v].second = v;
}
}
if (f[X].second < X)
cout << "Got caught!" << endl;
else
cout << f[X].first << endl;
return ;
}
HackerRank "Dorsey Thief"的更多相关文章
- codeforces 632+ E. Thief in a Shop
E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- HackerRank "Minimum Penalty Path"
It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- HackerRank Extra long factorials
传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...
- HackerRank "Lucky Numbers"
Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...
- HackerRank "Playing with numbers"
This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...
随机推荐
- 深入理解JVM内部结构(转)
图中显示的组件将会在下面两部分中进行逐一的解释.第一部分涉及JVM为每一个线程都会创建的组件:第二部分则是独立于线程进行创建的组件. 1. Thread Thread是一个程序中的一个 ...
- R语言决策树分类模型
rm(list=ls()) gc() memory.limit(4000) library(corrplot) library(rpart) data_health<-read.csv(&quo ...
- Spring Data Jpa 详解
前言: JPA全称Java Persistence API,即Java持久化API,它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据,结合其他ORM的使用,能达到简化开发 ...
- HDU 2083 简易版之最短距离 --- 水题
HDU 2083 简易版之最短距离 /* HDU 2083 简易版之最短距离 */ #include <cstdio> #include <algorithm> using n ...
- POJ1637 Sightseeing tour (混合图欧拉回路)(网络流)
Sightseeing tour Time Limit: 1000MS Me ...
- HDU-1011 Starship Troopers (树形DP+分组背包)
题目大意:给一棵有根带点权树,并且给出容量.求在不超过容量下的最大权值.前提是选完父节点才能选子节点. 题目分析:树上的分组背包. ps:特判m为0时的情况. 代码如下: # include<i ...
- java编程acm基础
java还是不错的昂! import java.util.*; import java.io.*; public class text{ static int a=100; public static ...
- Linux驱动设计——内存与IO访问
名词解释 内存空间与IO空间 内存空间是计算机系统里面非系统内存区域的地址空间,现在的通用X86体系提供32位地址,寻址4G字节的内存空间,但一般的计算机只安装256M字节或者更少的内存,剩下的高位内 ...
- JQuery之滑动幻灯片插件Easy Slider初体验
Easy Slider 是一个滑动幻灯片插件,支持任何图片或内容,可以实现横向或纵向滑动.它拥有一系列丰富的参数设置,可通过CSS来进行完全的控制.基本上只需要引入这个插件后,设置好内容,然后样式化C ...
- python课程
课程大纲 一.语言基础(5周) 数据类型 流程控制 模块 函数.迭代器.装饰器 递归.迭代.反射 面向对象编程 模拟人生游戏开发 二.网络编程(4周) Socket c/s编程.Twisted网络框架 ...