(第三场) A PACM Team 【dp,五维背包】

 

链接:https://www.nowcoder.com/acm/contest/141/A
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by coding(implementation ability), then math. However, in the ACM ICPC World Finals 2018, Eddy failed to solve a physics equation, which pushed him away from a potential medal.

Since then on, Eddy found that physics is actually the most important thing in the contest. Thus, he wants to form a team to guide the following contestants to conquer the PACM contests(PACM is short for Physics, Algorithm, Coding, Math).

There are N candidate groups each composed of p i physics experts, a i algorithm experts, c i coding experts, m i math experts. For each group, Eddy can either invite all of them or none of them. If i-th team is invited, they will bring g i knowledge points which is calculated by Eddy's magic formula. Eddy believes that the higher the total knowledge points is, the better a team could place in a contest. But, Eddy doesn't want too many experts in the same area in the invited groups. Thus, the number of invited physics experts should not exceed P, and A for algorithm experts, C for coding experts, M for math experts.

Eddy is still busy in studying Physics. You come to help him to figure out which groups should be invited such that they doesn't exceed the constraint and will bring the most knowledge points in total.

输入描述:

The first line contains a positive integer N indicating the number of candidate groups. Each of following N lines contains five space-separated integer p i, ai, ci, mi, gi indicating that i-th team consists of pi physics experts, ai algorithm experts, ci coding experts, mi math experts, and will bring gi knowledge points. The last line contains four space-separated integer P, A, C, M indicating the maximum possible number of physics experts, algorithm experts, coding experts, and math experts, respectively.
1 ≤ N ≤ 36 0 ≤ pi,ai,ci,mi,gi ≤ 36 0 ≤ P, A, C, M ≤ 36

输出描述:

The first line should contain a non-negative integer K indicating the number of invited groups. The second line should contain K space-separated integer indicating the index of invited groups(groups are indexed from 0).
You can output index in any order as long as each index appears at most once. If there are multiple way to reach the most total knowledge points, you can output any one of them. If none of the groups will be invited, you could either output one line or output a blank line in the second line.

case1:

输入

2

1 0 2 1 10

1 0 2 1 21

1 0 2 1

输出

1

1

case2:

输入

1 2 1 1 0 31

1 0 2 1

输出

0

 

 

题目大意:有一个四维背包,求取得最大值的方式(即有多少组,和具体组的 index)

思路:背包,但是要注意数据的类型要用short或者char,否则会爆内存。其次不能用滚动数组优化,因为要回溯到具体哪一组。做法一就是单纯的五维背包

状态:dp[ i ][ p ][ a ][ c ][ m ] 走了 i 组背包容量为 p, a, c, m 的最大值

状态转移: dp[ i ][ p ][ a ][ c ][ m ] = max(dp[i-1][ p ][ a ][ c ][ m ], dp[i-1][ p-ip[i] ][ a-ia[i] ][ c-ic[i] ][ m-im[i] ]);

这里回溯答案的话,用一个bool in[ i ][ p ][ a ][ c ][ m ]记录在当前状态有没有取第 i 组;

 

AC code:

 1 #include <vector>
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define INF 0x3f3f3f3f
 6 using namespace std;
 7 
 8 const int MAXN = 37;
 9 
10 short dp[MAXN][MAXN][MAXN][MAXN][MAXN];
11 int ip[MAXN], ia[MAXN], ic[MAXN], im[MAXN], g[MAXN];
12 bool in[MAXN][MAXN][MAXN][MAXN][MAXN];
13 int N, P, A, C, M;
14 
15 void slv()
16 {
17     for(int i = 0; i <= N; i++)      ///初始化
18     for(int p = 0; p <= P; p++)
19     for(int a = 0; a <= A; a++)
20     for(int c = 0; c <= C; c++)
21     for(int m = 0; m <= M; m++)
22         in[i][p][a][c][m] = false;
23 
24     for(int i = 1; i <= N; i++)
25     {
26         for(int p = 0; p <= P; p++)   ///省去下面比较前一个取或者不取,一律初始化为不取
27         for(int a = 0; a <= A; a++)
28         for(int c = 0; c <= C; c++)
29         for(int m = 0; m <= M; m++)
30         {
31             dp[i][p][a][c][m] = dp[i-1][p][a][c][m];
32         }
33         for(int p = P; p >= ip[i]; p--)
34         for(int a = A; a >= ia[i]; a--)
35         for(int c = C; c >= ic[i]; c--)
36         for(int m = M; m >= im[i]; m--)
37         {
38             if(dp[i][p][a][c][m] < (dp[i-1][p-ip[i]][a-ia[i]][c-ic[i]][m-im[i]]+g[i]))
39             {
40                 dp[i][p][a][c][m] = dp[i-1][p-ip[i]][a-ia[i]][c-ic[i]][m-im[i]]+g[i];
41                 in[i][p][a][c][m] = true;         ///取了第 i 组
42             }
43         }
44     }
45     vector<int>ans;
46     for(int i = N; i > 0; i--)
47     {
48         if(in[i][P][A][C][M])
49         {
50             ans.push_back(i-1);   ///题目下标从 0 开始
51             P-=ip[i];             ///但是这里数组下标是从 1 开始
52             A-=ia[i];
53             C-=ic[i];
54             M-=im[i];
55         }
56     }
57 
58     printf("%d\n", (int)ans.size());
59     for(size_t i = 0; i < ans.size(); i++)
60     {
61         printf("%d", ans[i]);
62         if(i+1 < ans.size()) printf(" ");
63         else printf("\n");
64     }
65 }
66 int main()
67 {
68     scanf("%d", &N);
69     for(int i = 1; i <= N; i++)
70     {
71         scanf("%d %d %d %d %d", &ip[i], &ia[i], &ic[i], &im[i], &g[i]);
72     }
73     scanf("%d %d %d %d", &P, &A, &C, &M);
74     slv();
75     return 0;
76 }

 

转载于:https://www.cnblogs.com/ymzjj/p/9381142.html

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值