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.

输入描述:

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

, a

i

, c

i

, m

i

, g

i

 indicating that i-th team consists of p

i

 physics experts, a

i

 algorithm experts, c

i

 coding experts, m

i

 math experts, and will bring g

i

 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 ≤ p

i

,a

i

,c

i

,m

i

,g

i

 ≤ 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.

输入例子:
2
1 0 2 1 10
1 0 2 1 21
1 0 2 1
输出例子:
1
1

-->

示例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

这题的b数组处理各种卡。。int五维爆内存,想用pair存map随用随开爆时间,然后就考虑降维,将标记数组b[n][VA][VB][VC][VD]=1的第一维下标表示在b元素中
b[VA][VB][VC][VD]=1ll<<(n-1),利用状压思想。注意因为2^36是long long级别的,所以1(一)的后面有一个ll(LL)常量类型转换。

赛后发现这道题五维时用bool或short就可以过。。而int是27wk(比赛限制26wk)印象中第一次被卡了内存囧

为此重温一下内存计算(64位):bool 1字节 short 2字节 int 4字节 long 8字节,1字节(B)=8位(bit),1024B=1k

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MAX = ;
const int INF = 0x3f3f3f3f; int dp[MAX][MAX][MAX][MAX];
int va[MAX],vb[MAX],vc[MAX],vd[MAX],w[MAX];
ll b[MAX][MAX][MAX][MAX]; int main(void)
{
int n,i,j,k,l,m;
int VA,VB,VC,VD;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d%d%d%d%d",&va[i],&vb[i],&vc[i],&vd[i],&w[i]);
}
scanf("%d%d%d%d",&VA,&VB,&VC,&VD);
for(i=;i<=n;i++){
for(j=VA;j>=va[i];j--){
for(k=VB;k>=vb[i];k--){
for(l=VC;l>=vc[i];l--){
for(m=VD;m>=vd[i];m--){
if(dp[j][k][l][m]<=dp[j-va[i]][k-vb[i]][l-vc[i]][m-vd[i]]+w[i]){
dp[j][k][l][m]=dp[j-va[i]][k-vb[i]][l-vc[i]][m-vd[i]]+w[i];
b[j][k][l][m]|=1ll<<(i-);
}
}
}
}
}
}
queue<int> q;
i=n;
while(i>&&VA>=&&VB>=&&VC>=&&VD>=){
if(b[VA][VB][VC][VD]&(1ll<<(i-))){
q.push(i-);
VA-=va[i];
VB-=vb[i];
VC-=vc[i];
VD-=vd[i];
}
i--;
}
printf("%d\n",q.size());
int f=;
while(q.size()){
if(f==) f=;
else printf(" ");
printf("%d",q.front());
q.pop();
}
printf("\n");
//printf("%d\n",dp[VA][VB][VC][VD]);
return ;
} /*
4
2 1 7 4 2
1 0 1 1 3
2 4 5 3 28
0 1 1 1 2
4 1 3 5
*/

牛客多校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. 【题解】POJ1934 Trip (DP+记录方案)

    [题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...

  2. BZOJ1217: [HNOI2003]消防局的设立

    BZOJ1217: [HNOI2003]消防局的设立 Description 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地. 起初为了节约材料,人类只修建了n-1条道路来连接这些基地 ...

  3. PopupWindow 实现 查看所有手机应用弹出框

    public class MainActivity extends Activity implements OnItemLongClickListener, OnClickListener { pri ...

  4. cetons 怎么强制卸载 PHP

    查看php版本命令: #php -v 这个命令是删除不干净的 #yum remove php 因为使用这个命令以后再用 #php -v 还是会看到有版本信息的..... 必须强制删除 #rpm -qa ...

  5. 【转】如何让虚拟目录里面的webconfig不继承网站的设置

    [转]http://www.cnblogs.com/Sue_/articles/2037556.html 必須在上一层虚拟目录(如根目录)所在的Web.config加上 如:<location ...

  6. Tomcat实现多主多备

    Nginx Upstream 实现简单双机主从热备 下面配置多主多从: upstream testproxy { server 127.0.0.1:8080; server 127.0.0.1:808 ...

  7. SQL Server 2008R2 代理服务-开启

    ,点击开始菜单-所有程序-SQLServer2008R2-配置工具-SQLServer配置管理器 2,选择SQLServer服务 3,找到SqlServer代理(MSSQLSERVER),双击或右键选 ...

  8. jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined

    原因:datatable表格内容有操作列,而表头没有定义操作列 少写了一行:<th>操作</th>

  9. Ubuntu 17.4下如何安装VMwareTools

    解压vmware-tools-distrib 运行vmware-install.pl安装过程中间出现错误,要求选择"ifconfig"工具.由于ifconfig工具过时逐渐被各大厂 ...

  10. rand()与srand()

    1.不用srand()的话 两次运行程序产生的随机数序列相同 2.用srand() 两次运行程序产生的随机数则不同 示例程序: #include<iostream> #include< ...