HDU 4341 分组背包
B - Gold miner
Time Limit:2000MS Memory Limit:32768KB
Description
Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help.
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.
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
There are multiple cases.
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)
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
Print the case number and the maximum value for each test case.
Sample Input
3 10
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 1: 3
Case 2: 7
题意:
黄金矿工的游戏
同一直线上的金子,只能先抓近的
题解:分组背包
///1085422276 #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=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //*************************************************************** struct ss { int x,y,v,t; }p[2050]; vector<ss >belong[2050]; 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[40005]; int main() { int oo=1; int n,m; while(scanf("%d%d",&n,&m)!=EOF) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++)belong[i].clear(); for(int i=1;i<=n;i++) { scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v); } p[0].x=-1; p[0].y=-1; sort(p+1,p+n+1,cmp); int zu=0; for(int i=1;i<=n;i++) { if(i!=1&&p[i].y*p[i-1].x==p[i].x*p[i-1].y) { ss kk; kk.v=belong[zu][belong[zu].size()-1].v+p[i].v; kk.t=belong[zu][belong[zu].size()-1].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=1;i<=zu;i++) { for(int j=m;j>=0;j--) { for(int k=0;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 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
· .NET开发智能桌面机器人:用.NET IoT库编写驱动控制两个屏幕
· 用纯.NET开发并制作一个智能桌面机器人:从.NET IoT入门开始
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· ASP.NET Core - 日志记录系统(二)
· 支付宝事故这事儿,凭什么又是程序员背锅?有没有可能是这样的...
· 在线客服系统 QPS 突破 240/秒,连接数突破 4000,日请求数接近1000万次,.NET 多
· C# 开发工具Visual Studio 介绍
· 在 Windows 10 上实现免密码 SSH 登录
· C#中如何使用异步编程