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 ...
随机推荐
- C#多线程学习 之 线程池[ThreadPool](转)
在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 这一般使用ThreadPo ...
- Vimer的福音 新时代的Vim C++自动补全插件 clang_complete
使用vim的各位肯定尝试过各种各样的自动补全插件,比如说大名鼎鼎的 OmniCppComplete .这一类的插件都是对 Ctags 生成的符号表进行字符串匹配来获得可能的补全项.他们在编写 C 代码 ...
- Responsive设计的十个基本技巧(转)
什么是Responsive设计?有的同学认为Responsive设计是自适应布局,也有的同学认为Responsive是网格布局.其实这些想法都不正确.Wikipedia对Responsive做 了详细 ...
- linux命令合集
序:介绍一些经常需要用到的Linux命令. 一.wget 作用:下载网络文件,将远程服务器文件恢复备份到本地. wget http://cn.wordpress.org/wordpress-3.1-z ...
- 简单聊下Unicode和UTF-8
今晚听同事分享提到这个,简单总结下. ## Unicode字符集 Unicode的出现是因为ASCII等其他编码码不够用了,比如ASCII是英语为母语的人发明的,只要一个字节8位就能够表示26个英文字 ...
- HDOJ 1524 A Chess Game
A Chess Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- upc.2219: A^X mod P(打表 && 超越快速幂(in some ways))
2219: A^X mod P Time Limit: 5 Sec Memory Limit: 128 MB Submit: 417 Solved: 68 [Submit][Status][Web ...
- Swift Tour 随笔总结 (4)
Switch的一个例子: let vegetable = "red pepper" switch vegetable { case "celery": let ...
- HDU 1018 Big Number (数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x ...
- HDU 4435 charge-station () bfs图论问题
E - charge-station Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...