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

题目描述

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 pi physics experts, ai algorithm experts, ci coding experts, mi 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 gi 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.

示例1
2
1 0 2 1 10
1 0 2 1 21
1 0 2 1

输出

1
1

示例2

输入

1
2 1 1 0 31
1 0 2 1

输出

0

题意按照我的理解就是相当于一个具有多个重量W的01背包。就是从一个W扩展到P,A,C,M四个属性。大概做法就是按照01背包的样式进行改写就可以了,因为范围很小只有36,所以时间复杂度就是个五层的循环,大概O(pow(36,5)) = 6000w左右,不会超时,这里要降一层数组,就是4层的一个dp数组就够了。也不会超内存.使用记录路径的方法,直到最后再还原回去把加入的物品记录下来最后再输出。也就是一个很裸的做法。
#include <bits/stdc++.h>using namespace std;const int m=40;struct node{int P,A,C,M,G;
}a[m];int A,B,C,D;
int N;
int dp[m][m][m][m];
bool path[m][m][m][m][m]={0};//用int超内存了int main()
{scanf("%d",&N);for(int i=0;i<N;i++){scanf("%d%d%d%d%d",&a[i].P,&a[i].A,&a[i].C,&a[i].M,&a[i].G);}scanf("%d%d%d%d",&A,&B,&C,&D);for(int i=0;i<N;i++){for(int j=A;j>=a[i].P;j--){for(int k=B;k>=a[i].A;k--){for(int l=C;l>=a[i].C;l--){for(int o=D;o>=a[i].M;o--){if(dp[j][k][l][o]<dp[j-a[i].P][k-a[i].A][l-a[i].C][o-a[i].M]+a[i].G){dp[j][k][l][o]=dp[j-a[i].P][k-a[i].A][l-a[i].C][o-a[i].M]+a[i].G;path[i][j][k][l][o] = 1;}}}}}}vector<int> ans;for(int i=N-1; i>=0 && A>=0 && B>=0 && C >=0 && D>=0 ;i--) {if(path[i][A][B][C][D]) {ans.push_back(i);A -= a[i].P,B -= a[i].A;C -= a[i].C,D -= a[i].M;}}int sz = ans.size();printf("%d\n",sz);for(int i=0;i<sz;i++) {printf(i==sz-1?"%d\n":"%d ",ans[i]);}return 0;
}

转载于:https://www.cnblogs.com/Fy1999/p/9384061.html

牛客网暑期ACM多校训练营(第三场)A.PACM Team(多重01背包)相关推荐

  1. 牛客网暑期ACM多校训练营(第三场): E. Sort String(KMP)

    链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a ...

  2. 牛客网暑期ACM多校训练营(第三场): C. Shuffle Cards(splay)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  3. 牛客网暑期ACM多校训练营(第三场): A. Ternary String(欧拉降幂+递推)

    题目描述 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a t ...

  4. 牛客网暑期ACM多校训练营(第三场): C. Chiaki Sequence Reloaded(数位DP)

    题目描述 Chiaki is interested in an infinite sequence a1, a2, a3, ..., which defined as follows: Chiaki ...

  5. 牛客网暑期ACM多校训练营(第九场)

    牛客网暑期ACM多校训练营(第九场) A. Circulant Matrix 做法:看到下标 \(xor\) 这种情况就想 \(FWT\),可是半天没思路,于是放弃了..其实这个 \(n\) 疯狂暗示 ...

  6. 牛客网暑期ACM多校训练营(第一场)

    牛客网暑期ACM多校训练营(第一场) A. Monotonic Matrix 考虑0和1的分界线,1和2的分界线,发现问题可以转化为两条不互相穿过的路径的方案数(可重叠),题解的做法就是把一条路径斜着 ...

  7. 牛客网暑期ACM多校训练营(第二场): H. travel(树形线头DP)

    链接:https://ac.nowcoder.com/acm/contest/140/H 来源:牛客网 题目描述 White Cloud has a tree with n nodes.The roo ...

  8. 牛客网暑期ACM多校训练营(第二场)A .run

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 题目描述 White Cloud is exercising in the playgroun ...

  9. 牛客网暑期ACM多校训练营(第一场) J (莫队算法)

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目大意:给一个序列,进行q次查询,问1~l和r~n中有多少个不同的数字 题目思路:之前只是听说过莫队算 ...

  10. 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)

    题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...

最新文章

  1. 【新浪上海】上海信息化建设进入新阶段 首席信息官联盟发挥重要作用
  2. 计算机配置里面没有网络选项,主编教您win10网络设置中没有wlan选项怎么办
  3. CVPR 2019 | 无监督领域特定单图像去模糊
  4. MicroPython (一)点亮我的Led
  5. 能从入门到精通的 Docker 学习指南
  6. mysql查询问题解答_mysql查询问题
  7. Linux常用基础命令3
  8. 在线扒站复活版可预览网站html源码
  9. Docker学习之镜像删除的Untagged 和 Deleted
  10. 1976国际标准大气_Matlab
  11. url 转码 java_URL 转码遇到的坑
  12. 扫地机器人朋友圈文案_扫地机器人的简单文案
  13. docker pull报错:Timeout exceeded while awaiting headers解决思路
  14. JWT的讲解以及JJWT的使用(另附JWT工具类)
  15. 裴蜀定理与扩展欧几里德算法
  16. 小米跳智能家居大坑,丢芝麻捡西瓜值得吗?
  17. vw 前端_px转vw和vh的工具(对前端同学有用)
  18. 计算机xp重装无声音怎么办,WinXP电脑声音不正常的处理方法
  19. 黑群晖升级后无法找到的方法
  20. linux 详解邮件服务器

热门文章

  1. [Sdoi2010]古代猪文
  2. linux环境变量与文件查找
  3. 通过实现继承TabActivity并且实现TabContentFactory的方法创建选项卡的一点心得
  4. 记录一个海思TOE的BUG
  5. Linux popen和pclose启动shell命令的问题思考
  6. 计算机基础ABCDEF,计算机应用基础-在线作业ABCDEF.docx
  7. Codis安装与部署
  8. 钉钉宜搭入选Forrester《中国低代码平台市场分析报告》
  9. 【计算机视觉】究竟谁能解决可解释性 AI?
  10. 你的Wi-Fi 还安全吗?全球重大漏洞WPA2 KRACK 详细分析报告