HDU 4341 Gold miner (分组背包问题)

本文介绍了一种解决游戏金币收集问题的算法。通过将金币位置排序并按斜率分组,确保共线金币按顺序获取。使用分组背包方法求解最大价值路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gold miner

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1124    Accepted Submission(s): 458

Problem 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.  

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)  

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  

思路:题目由于对于共线的点,必须按顺序去拿,可以按点的x做升序排序,然后把斜率相同的点分到同一个组。对于同组的点,第一个点的价值为v1,时间为t1,第二个点的价值为v1+v2,时间为t1+t2,接下来是v1+v2+v3,t1+t2+t3...以此类推,这样就能保证同组里的每一个物品是互斥的,并且是按顺序去拿的。分组分好以后,就是直接按分组背包的做法做了。

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #define MAX 40005
 7 #define SIZE 205
 8 
 9 using namespace std;
10 
11 struct Gold
12 {
13     int x,y,t,v;
14 };
15 
16 int line[SIZE][SIZE],num[SIZE]; //line存储分组情况,其中line[1][1]代表的是第一组第一个物品,num存的是该组里物品的件数
17 bool used[SIZE]; //判断该物品是否已经被纳入一个物品组中
18 Gold gold[SIZE];
19 int dp[MAX];
20 int N,T;
21 
22 bool cmp(Gold a,Gold b) //升序
23 {
24     return abs(a.x) < abs(b.x);
25 }
26 
27 void init()
28 {
29     memset(dp,0,sizeof(dp));
30     memset(line,0,sizeof(line));
31     memset(num,0,sizeof(num));
32     memset(used,0,sizeof(used));
33 }
34 
35 int main()
36 {
37     int Case = 1;
38     while(~scanf("%d%d",&N,&T))
39     {
40         for(int i=1; i<=N; i++)
41             scanf("%d %d %d %d",&gold[i].x, &gold[i].y, &gold[i].t, &gold[i].v);
42         sort(gold+1, gold+1+N, cmp);
43         init();
44         int index = 1;
45         for(int i=1; i<=N; i++) //分组
46         {
47             if(used[i])continue;
48             used[i] = true;
49             line[index][++num[index]] = i; //存储该组的第一件物品
50             for(int j=i+1; j<=N; j++)
51             {
52                 if(!used[j] && gold[i].x*gold[j].y == gold[i].y*gold[j].x)
53                 {
54                     line[index][++num[index]] = j; //把斜率相同的放到同个组
55                     used[j] = true;
56                 }
57             }
58             index ++;
59         }
60         index --;
61         for(int i=1; i<=index; i++) //更新组成员的价值和时间
62         {
63             for(int j=2; j<=num[i]; j++)
64             {
65                 gold[line[i][j]].t += gold[line[i][j-1]].t;
66                 gold[line[i][j]].v += gold[line[i][j-1]].v;
67             }
68         }
69         for(int i=1; i<=index; i++) //分组背包
70         {
71             for(int j=T; j>=0; j--)
72             {
73                 for(int k=1; k<=num[i]; k++)
74                     if(j-gold[line[i][k]].t>=0)
75                         dp[j] = max(dp[j],dp[j-gold[line[i][k]].t]+gold[line[i][k]].v);
76             }
77         }
78         printf("Case %d: %d\n",Case++,dp[T]);
79     }
80     return 0;
81 }

 

内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值