链接: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. BZOJ 3878 【AHOI2014】 奇怪的计算器

    题目链接:奇怪的计算器 如果没有溢出的话,所有的标记都可以在线段树上直接维护,所以一棵线段树就解决问题了. 现在有了溢出,怎么办呢? 发现就算溢出了,各个元素的相对大小关系也是不变的.所以,如果一开始 ...

  2. vs2013 报错error C1083: 无法打开包括文件:“gl\glew.h”: No such file or directory\

    vs报错诸如如无法打开“gl\xxx.h”时, 解决方法: 1.去http://glew.sourceforge.net/下载相关文件,2.在下载下来的文件里找到xxx.h,将其复制到vs的相关目录下 ...

  3. C#_方法的重载

    方法的重载是一种操作性多态,有的时候,可能需要在多个不同的实现中对不同的数据执行相同的逻辑操作,以writeline方法为例,有时可能想他传递一个整数.两者的具体实现肯定是不同的,但在逻辑上,这个方法 ...

  4. hive表的存储路径查找以及表的大小

    1.在hive中知道一个表的存储路径可以通过hive命令   desc formatted table_name 显示表的详细信息; 2.然后找到该表的存储路径 "Location:    ...

  5. nginx 启动报错 1113: No mapping for the Unicode character exists in the target multi-byte code

    failed (1113: No mapping for the Unicode character exists in the target multi-byte code page) 因为路径有中 ...

  6. HYPERSPECTRAL IMAGE CLASSIFICATION USING TWOCHANNEL DEEP CONVOLUTIONAL NEURAL NETWORK阅读笔记

    HYPERSPECTRAL IMAGE CLASSIFICATION USING TWOCHANNEL  DEEP  CONVOLUTIONAL NEURAL NETWORK 论文地址:https:/ ...

  7. ButterKnife RadioGroup选择事件

    ButterKnife 的点击事件都很清晰,在使用RadioGroup控件时的方法: <!-- 定义一组单选框 --> <RadioGroup android:id="@+ ...

  8. Qt5获取本机网络信息

    获取本机网络信息 在pro文件中加入如下代码 QT += network widget.h中的代码如下 #ifndef WIDGET_H #define WIDGET_H #include <Q ...

  9. Linux实际常用命令

    1.删除0字节文件 find -type f -size 0 -exec rm -rf {} \;  2.查看进程 按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sor ...

  10. Codeforces 813E - Army Creation

    813E - Army Creation 思路: 线段树+二分 先预处理每个点往后走k步的下标 线段树二叉树的每个节点用vector维护这些下标,给这些下标排个序 询问区间L,R,那么把下标小于等于R ...