链接: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 , 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.
输入描述:
The first line contains a positive integer N indicating the number of candidate groups.
Each of following N lines contains five space-separated integer pi, 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.   ≤ N ≤
  ≤ pi,ai,ci,mi,gi ≤
  ≤ P, A, C, M ≤
输出描述:
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 ). 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
输入 复制 输出 复制

一开始写了五维,内存超限了

36我们发现2的36次不会超ll

所以用状压去存路径

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
struct node
{
int a,b,c,d,v;
}p[37];
int dp[37][37][37][37];
ll path[37][37][37][37];
int main()
{
int n;
scanf("%d",&n);
memset(dp,0,sizeof(dp));
memset(path,0,sizeof(path));
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d%d",&p[i].a,&p[i].b,&p[i].c,&p[i].d,&p[i].v);
}
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
for(int i=0;i<n;i++)
{
for(int j=a;j>=0;j--)
for(int k=b;k>=0;k--)
for(int q=c;q>=0;q--)
for(int w=d;w>=0;w--)
{
if(p[i].a>j||p[i].b>k||p[i].c>q||p[i].d>w)
continue;
else if(dp[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]+p[i].v>dp[j][k][q][w])
{
dp[j][k][q][w]=dp[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]+p[i].v;
path[j][k][q][w]=path[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]|(1ll<<i);
}
}
}
//cout<<dp[a][b][c][d]<<endl;
//cout<<path[a][b][c][d]<<endl;
int f=0;
int p[1000];
for(int i=0;i<n;i++)
{
if(path[a][b][c][d]&(1ll<<i))
{
p[f++]=i;
}
}
cout<<f<<endl;
for(int i=0;i<f;i++)
{
if(i)printf(" ");
printf("%d",p[i]);
}
printf("\n"); return 0;
}

牛客多校第三场 A—pacm team (4维背包加路径压缩)的更多相关文章

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

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

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

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

  3. 牛客多校第三场-A-PACM Team-多维背包的01变种

    题目我就不贴了...说不定被查到要GG... 题意就是我们需要在P,A,C,M四个属性的限制下,找到符合条件的最优解... 这样我们就需要按照0/1背包的思路,建立一个五维度数组dp[i][j][k] ...

  4. 牛客多校第三场 A- PACM Team 背包/记忆路径

    https://www.nowcoder.com/acm/contest/141#question 一眼背包,用四维dp记录在A,B,C,D条件限制下可以获得的最大知识点,但是题目要求输出路径,在输入 ...

  5. 牛客网多校训练第三场 A - PACM Team(01背包变形 + 记录方案)

    链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai, ...

  6. 2018牛客多校第三场 C.Shuffle Cards

    题意: 给出一段序列,每次将从第p个数开始的s个数移到最前面.求最终的序列是什么. 题解: Splay翻转模板题.存下板子. #include <bits/stdc++.h> using ...

  7. Removing Stones(2019年牛客多校第三场G+启发式分治)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 初始时有\(n\)堆石子,每堆石子的石子个数为\(a_i\),然后进行游戏. 游戏规则为你可以选择任意两堆石子,然后从这两堆中移除一个石子,最 ...

  8. 2019年牛客多校第三场 F题Planting Trees(单调队列)

    题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...

  9. 2019牛客多校第三场 F.Planting Trees

    题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ...

随机推荐

  1. git服务器搭建全程

    为了后续安装能正常进行,我们先来安装一些相关依赖库和编译工具 [root@VM_95_113_centos ~]# yum install curl-devel expat-devel gettext ...

  2. ECMAScript6语法重点(一)

    一. let和const ①let声明的变量只在它的块作用域有效({ }括起来) ②let不能重复声明同一变量 ③const声明的常量不能改(但对象可以加属性) ④const也有块作用域概念 ⑤con ...

  3. 二: vue的属性及功能,axios

    一: 过滤器 1. 定义:    过滤器,就是vue允许开发者自定义的文本格式化函数,可以使用在两个地方:输出内容和操作数据中. 定义过滤器的方式有两种. 2.使用vue.filter()进行全局定义 ...

  4. Discrete Log Algorithms :Baby-step giant-step 【二】

    import gmpy2 def discreteLog(g,p,a): #离散对数,求 g^x=a mod p中的x table={} sq=gmpy2.isqrt(p-1) m=gmpy2.add ...

  5. 力扣(LeetCode) 997. 找到小镇的法官

    在一个小镇里,按从 1 到 N 标记了 N 个人.传言称,这些人中有一个是小镇上的秘密法官. 如果小镇的法官真的存在,那么: 小镇的法官不相信任何人. 每个人(除了小镇法官外)都信任小镇的法官. 只有 ...

  6. Qt5标准文件对话框类

    getOpenFileName()函数返回用户选择的文件名,其函数形式如下: QString QFileDialog::getOpenFileName(QWidget *parent = Q_NULL ...

  7. EOJ Monthly 2018.11 D. 猜价格

    猜价格 分两种情况讨论: k≤n,先猜至多 k 次 1,由于回答 <1 肯定是假的,所以可以把剩余系下是哪次错试出来,然后用至多 n 次搞定. k>n,每个数都猜两次,如果两次结果不一样, ...

  8. Python数据分析-Day1-Numpy模块

    1.numpy.genfromtxt读取txt文件 import numpyworld_alcohol = numpy.genfromtxt("world_alcohol.txt" ...

  9. legend2---开发日志2(注释和函数比较好的写法)

    legend2---开发日志2(注释和函数比较好的写法) 一.总结 一句话总结: 函数用_接意群 注释的关键字用[]括起来 注释的步骤用中文的步骤二字 1.为何以步骤为名写注释? 结构非常清晰 //步 ...

  10. 放弃 Tightvnc, 选择 Tigervnc

    构建headless vnc server ,我终于放弃了Tightvnc 基于以下原因: 1) 已知的Qt5的键盘映射问题,导致virtualbox 的使用出现困难 https://unix.sta ...