PACM Team

链接: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 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. 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

  1. , a

i

  1. , c

i

  1. , m

i

  1. , g

i

  1. indicating that i-th team consists of p

i

  1. physics experts, a

i

  1. algorithm experts, c

i

  1. coding experts, m

i

  1. math experts, and will bring g

i

  1. 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.
  2.  
  3.  1 N 36
     0 p

i

  1. ,a

i

  1. ,c

i

  1. ,m

i

  1. ,g

i

  1. 36
     0 P, A, C, M 36

输出描述:

  1. 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).
  2.  
  3. 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.

输入例子:
  1. 2
  2. 1 0 2 1 10
  3. 1 0 2 1 21
  4. 1 0 2 1
输出例子:
  1. 1
  2. 1

-->

示例1

输入

复制

  1. 2
  2. 1 0 2 1 10
  3. 1 0 2 1 21
  4. 1 0 2 1

输出

复制

  1. 1
  2. 1
示例2

输入

复制

  1. 1
  2. 2 1 1 0 31
  3. 1 0 2 1

输出

复制

  1. 0
  2.  
  3. 这题的b数组处理各种卡。。int五维爆内存,想用pairmap随用随开爆时间,然后就考虑降维,将标记数组b[n][VA][VB][VC][VD]=1的第一维下标表示在b元素中
  1. b[VA][VB][VC][VD]=1ll<<(n-1),利用状压思想。注意因为2^36long long级别的,所以1(一)的后面有一个llLL)常量类型转换。
  2.  
  3. 赛后发现这道题五维时用boolshort就可以过。。而int27wk(比赛限制26wk)印象中第一次被卡了内存囧
  4.  
  5. 为此重温一下内存计算(64位):bool 1字节 short 2字节 int 4字节 long 8字节,1字节(B)=8位(bit),1024B=1k
  1.  
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. const int MAX = ;
  7. const int INF = 0x3f3f3f3f;
  8.  
  9. int dp[MAX][MAX][MAX][MAX];
  10. int va[MAX],vb[MAX],vc[MAX],vd[MAX],w[MAX];
  11. ll b[MAX][MAX][MAX][MAX];
  12.  
  13. int main(void)
  14. {
  15. int n,i,j,k,l,m;
  16. int VA,VB,VC,VD;
  17. scanf("%d",&n);
  18. for(i=;i<=n;i++){
  19. scanf("%d%d%d%d%d",&va[i],&vb[i],&vc[i],&vd[i],&w[i]);
  20. }
  21. scanf("%d%d%d%d",&VA,&VB,&VC,&VD);
  22. for(i=;i<=n;i++){
  23. for(j=VA;j>=va[i];j--){
  24. for(k=VB;k>=vb[i];k--){
  25. for(l=VC;l>=vc[i];l--){
  26. for(m=VD;m>=vd[i];m--){
  27. if(dp[j][k][l][m]<=dp[j-va[i]][k-vb[i]][l-vc[i]][m-vd[i]]+w[i]){
  28. dp[j][k][l][m]=dp[j-va[i]][k-vb[i]][l-vc[i]][m-vd[i]]+w[i];
  29. b[j][k][l][m]|=1ll<<(i-);
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. queue<int> q;
  37. i=n;
  38. while(i>&&VA>=&&VB>=&&VC>=&&VD>=){
  39. if(b[VA][VB][VC][VD]&(1ll<<(i-))){
  40. q.push(i-);
  41. VA-=va[i];
  42. VB-=vb[i];
  43. VC-=vc[i];
  44. VD-=vd[i];
  45. }
  46. i--;
  47. }
  48. printf("%d\n",q.size());
  49. int f=;
  50. while(q.size()){
  51. if(f==) f=;
  52. else printf(" ");
  53. printf("%d",q.front());
  54. q.pop();
  55. }
  56. printf("\n");
  57. //printf("%d\n",dp[VA][VB][VC][VD]);
  58. return ;
  59. }
  60.  
  61. /*
  62. 4
  63. 2 1 7 4 2
  64. 1 0 1 1 3
  65. 2 4 5 3 28
  66. 0 1 1 1 2
  67. 4 1 3 5
  68. */

牛客多校3 A-PACM Team(状压降维+路径背包)的更多相关文章

  1. 牛客 26E 珂学送分2 (状压dp)

    珂...珂...珂朵莉给你出了一道送分题: 给你一个长为n的序列{vi},和一个数a,你可以从里面选出最多m个数 一个合法的选择的分数定义为选中的这些数的和加上额外规则的加分: 有b个额外的规则,第i ...

  2. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  3. 牛客多校第一场 B Inergratiion

    牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...

  4. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  5. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  6. 牛客多校第三场 G Removing Stones(分治+线段树)

    牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...

  7. 牛客多校第四场sequence C (线段树+单调栈)

    牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...

  8. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  9. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

随机推荐

  1. 消息队列activeMq 使用介绍

      深入浅出 消息队列 ActiveMQhttp://blog.csdn.net/jwdstef/article/details/17380471 一. 概述与介绍 ActiveMQ 是Apache出 ...

  2. CrystalReport runtime的下载地址

    SAP网站的东西实在太多了,找个CrytalReport都费劲.13.*版的可以通过下面的地址下载: SAP Crystal Reports, developer version for Micros ...

  3. Ubuntu编译Android使用的FFmpeg

    本文介绍在Ubuntu平台编译FFmpeg库,用于Android使用.前提需要配置好NDK的环境.可以参考之前的文章Android NDK环境搭建. 下载FFmpeg 在官网下载FFmpeg源码,ht ...

  4. Git core objects

    Git core objects Core objects in git blob object tree object commit object Git low level commands gi ...

  5. sqrt源码

    先找出接近m的浮点数,然后通过下面的不等式中的等于条件得到其平方根. #include <iostream> #include <math.h> using namespace ...

  6. POJ 之 WERTYU

    WERTYU Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8371   Accepted: 4007 Descriptio ...

  7. redis简介及安装

    1 redis简介及安装 1.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. 首 ...

  8. 安装与设置hexo

    普通用户(非全局)安装nodejs和npm wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh nvm ins ...

  9. 一些rtsp实现的开源代码

    * live.com   C/S   C++   http://www.live555.com     * darwin     S     C++   http://www.opensource.a ...

  10. 使用msiexec提取msi包里的文件

    核心:如需把d盘下abc.msi文件解包到目录d:\abc,操作如下:打开命令提示符,输入msiexec /a "d:\abc.msi" /qb TARGETDIR="D ...