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 ...
随机推荐
- Ubuntu如何安装secureCRT
以前在ubuntu上安装过secureCRT,是自己按照网上的教程安装的. 电脑重装了系统之后,想在电脑上安装一个,又得去网上搜,安装完后,自己总结了一下. 1,下载secureCRT包 根据自己电脑 ...
- ajax 之js读取xml的多浏览器兼容
主要是分为两大类:IE.其它浏览器 IE8以下只支持这种 InputVoltage.innerText = xmlDoc.getElementsByTagName(id)[0].text, 其它浏览器 ...
- php面试题之五——MySQL数据库(基础部分)
五.MySQL数据库 mysql_num_rows() mysql_affected_rows() 这两个函数都作用于 mysql_query($query)操作的结果,mysql_num_rows( ...
- Sqli-LABS通关笔录-1
在第一个关卡当中还是学到些知识. 1.注释语句多试试其他的几个 2.不报错可能是前面的语句没有错误,union没有得到执行. http://127.0.0.1/sql/Less-1/index.php ...
- 秀尔算法:破解RSA加密的“不灭神话”
RSA加密 VS 秀尔算法 作为RSA加密技术的终结者——“太多运算,无法读取”的秀尔算法(Shor’s algorithm)不是通过暴力破解的方式找到最终密码的,而是利用量子计算的并行性,可以快速分 ...
- zoj3745 Salary Increasing
OJ Problem Set - 3745 Salary Increasing Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has ...
- Dynamo和Bigtable对比
数据结构化问题 首先要提到的是两者存储数据属性上的区别,虽然两者都是以key/value形式进行存储,但Dynamo偏向存储原数据,因为其所存储的数据是非结构化数据,对value的解析完 ...
- ZJOI 游记
在备战YZ提前招生考时去ZJOI玩了趟,ZJ果然人才辈出= =神犇讲课各种神听不懂啊orz day 0 Mon. 上午在AB班愉快地玩耍,下午就去HZ了. HZ真热啊... 学军也是节约= =空调都不 ...
- A PHP extension for Facebook's RocksDB
A PHP extension for Facebook's RocksDB 31 commits 2 branches 0 releases 2 contributors C++ 90.5% C 8 ...
- XPath学习:轴(3)——descendant
XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQuery 和 XPointe ...