HDU 4341 分组背包
Time Limit:2000MS
Description
To make it easy, the gold becomes a point (with the area of 0). You are given each gold's position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately.
Please help Homelesser get the maximum value.
Input
In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0<N≤200, 0≤T≤40000)
In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0<y≤200,0<t≤200, 0≤v≤200)
Output
Sample Input
1 1 1 1
2 2 2 2
1 3 15 9
3 10
1 1 13 1
2 2 2 2
1 3 4 7
Sample Output
Case 2: 7
///
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//*************************************************************** struct ss
{
int x,y,v,t;
}p[];
vector<ss >belong[];
bool cmp(ss a,ss b)
{
if(a.y*b.x!=a.x*b.y)
return a.y*b.x<a.x*b.y;
else return a.y<b.y;
}
int dp[];
int main()
{ int oo=;
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)belong[i].clear();
for(int i=;i<=n;i++)
{
scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v);
}
p[].x=-;
p[].y=-;
sort(p+,p+n+,cmp);
int zu=;
for(int i=;i<=n;i++)
{
if(i!=&&p[i].y*p[i-].x==p[i].x*p[i-].y)
{
ss kk;
kk.v=belong[zu][belong[zu].size()-].v+p[i].v;
kk.t=belong[zu][belong[zu].size()-].t+p[i].t;
belong[zu].push_back(kk);
}
else {
ss kk;
kk.v=p[i].v;
kk.t=p[i].t;
belong[++zu].push_back(kk);
} }
//cout<<3213121<<endl;
for(int i=;i<=zu;i++)
{
for(int j=m;j>=;j--)
{
for(int k=;k<belong[i].size();k++)
{
if(j>=belong[i][k].t)
{
dp[j]=max(dp[j],dp[j-belong[i][k].t]+belong[i][k].v);
}
}
}
}
printf("Case %d: %d\n",oo++,dp[m]); } return ;
}
代码狗
HDU 4341 分组背包的更多相关文章
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- ACboy needs your help(HDU 1712 分组背包入门)
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1712 (分组背包入门)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 问题 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组, ...
- HDU 3033 分组背包变形(每种至少一个)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3033 分组背包(至少选一个)
分组背包(至少选一个) 我真的搞不懂为什么,所以现在就只能当作是模板来用吧 如果有大牛看见 希望评论告诉我 &代码: #include <cstdio> #include < ...
- HDU 3033 分组背包
给出N个物品.M金钱.W种类 给出N个物品的性质:所属种类,花费.价值 求每一种类物品至少一个的前提下,所能购买到的最大价值 dp[i][k]表示在第i种物品.总花费为k的最大价值 dp[i][k]= ...
- 背包系列 hdu 3535 分组背包
题意: 有n组工作,现在有T分钟时间去做一些工作.每组工作里有m个工作,并且类型为s,s类型可以为0,1,2,分别表示至少选择该组工作的一项,至多选择该工作的一项,不限制选择.每个工作有ci,gi两个 ...
- 【HDU - 4341】Gold miner(分组背包)
BUPT2017 wintertraining(15) #8B 题意 给出每个黄金的坐标.价值及耗时,同一方向的黄金只能依次取,求T时间内收获的最大值. 题解 同一方向,物品前缀和构成的组合,相当于是 ...
- HDU 4341 Gold miner (分组背包)
先把线按照距离原点的距离排序,然后用叉积把在同一条直线上的点放在一起, 把在同一条线上的点中的前i个点当成一个点就转化成了分组背包. 写if(kas++) putchar('\n') 居然PE了,PE ...
随机推荐
- MySql开启事务
CREATE PROCEDURE test_sp1( ) BEGIN ; ; START TRANSACTION; INSERT INTO test VALUES(NULL, 'test sql 00 ...
- ES+Hbase对接方案概述
方案背景 Hbase的索引方案有很多,越来越多的人开始选择ES+Hbase的方案,其实该方案并没有想象中那么完美,ES并发低,同时查询速度相对Hbase也慢很多,那为什么会选择他呢,它的写入比较快,如 ...
- MySQL获取随机数
如何通过MySQL在某个数据区间获取随机数? MySQL本身提供一个叫rand的函数,返回的v范围为0 <= v < 1.0. 介绍此函数的MySQL文档也介绍道,可以通过此计算公式FLO ...
- css实现固定高度及未知高度文字垂直居中的完美解决方案
在工作当中我们经常碰到类似于"固定高度文字垂直居中及未知高度垂直居中问题",或者 "图片垂直居中问题",而我们最容易会想到使用表格来垂直居中,或者如果是单行文字 ...
- [Effective JavaScript 笔记]第41条:将原型视为实现细节
对象原型链 一个对象给其使用者提供了轻量.简单.强大的操作集.使用者与一个对象最基本的交互是获取其属性值和调用其方法.这些操作不是特别在意属性存储在原型继承结构的哪个位置.随着时间推移,实现对象时可能 ...
- jekyll中文乱码问题
一般编写都是采用utf-8的吧,但是在windows下安装的jekyll,默认是以GBK编码的方式去读取咱们编写的文件,如此便乱码了. 要解决此问题,总不至于要写GBK编码的文件吧,毕竟这个编码不怎么 ...
- 20个很有用的PHP类库
介绍20个非常有用的PHP类库,相信一定可以为你的WEB开发提供更好和更为快速的方法. 图表库 下面的类库可以让你很简的创建复杂的图表和图片.当然,它们需要GD库的支持. pChart – 一个可以创 ...
- sharepoint部件webparth关闭找回的方法
- VIM替换、截取及追加操作
参考: http://blog.csdn.net/love__coder/article/details/6739670 http://blog.csdn.net/love__coder/articl ...
- iOS 定义圆角控件
ios7 以前,想把UILabel变为圆角的,只需要设置layer的 cornerRadius属性,ios7以后,还需要设置 masksToBounds = true. 以下是这个属性的说明 A Bo ...