牛客多校3 A-PACM Team(状压降维+路径背包)
PACM Team
链接:https://www.nowcoder.com/acm/contest/141/A
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
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
-->
输出
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(状压降维+路径背包)的更多相关文章
- 牛客 26E 珂学送分2 (状压dp)
珂...珂...珂朵莉给你出了一道送分题: 给你一个长为n的序列{vi},和一个数a,你可以从里面选出最多m个数 一个合法的选择的分数定义为选中的这些数的和加上额外规则的加分: 有b个额外的规则,第i ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 牛客多校第四场sequence C (线段树+单调栈)
牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
随机推荐
- 设计模式系列一创建型模式之(简单工厂VS工厂方法)
1.简单工厂简介 诞生背景:在我们平常编程当中,经常会使用new进行实例化一个对象,此时该类完全依赖于该对象,专业术语来说就是耦合度高.当需求发生变化时我们不得不去修改此类的源码,造成整个系统难以维护 ...
- c++对象内存的分配
1 关于c++的对象 只要是用了class或者struct定义的,都是对象,不管有没有方法.不过,一般情况下,没有方法的对象用struct关键字来定义. 2 不用new关键字定义对象 要看这样的对象在 ...
- 我的Java开发学习之旅------>Java经典排序算法之插入排序
一.算法原理 插入排序法:所谓插入排序法乃是将一个数目插入该占据的位置. 假设我们输入的是 "53,27,36,15,69, 42" 我们从第二个数字开始,这个数字是27,我们的 ...
- 【python】python调用shell方法
在python脚本中,有时候需要调用shell获取一下信息,下面介绍两种常用的调用方法. 第一种,os.system() 这个函数获取的是命令的执行状态,比如 >>> import ...
- python3用pdfminer3k在线读取pdf文件
import importlib import sys import random from urllib.request import urlopen from urllib.request imp ...
- ubuntu把文件移动到指定的文件夹
有个文件a.txt在/etc下,想把它移动到/etc/fuck文件夹中 cd /etc/fuck sudo mv a.txt 要移动到的文件夹 没报错就成功了
- ruby 字符串
字符串处理函数 1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fa ...
- 吴恩达机器学习笔记(六) —— 支持向量机SVM
主要内容: 一.损失函数 二.决策边界 三.Kernel 四.使用SVM (有关SVM数学解释:机器学习笔记(八)震惊!支持向量机(SVM)居然是这种机) 一.损失函数 二.决策边界 对于: 当C非常 ...
- Contiki Network Stack
一.协议栈 主要有两大网络协议栈,uIP和Rime这两大协议栈(network stack): The uIP TCP/IP stack, which provides us with IPv4 ne ...
- 线上cpu100%问题快速定位
问题描述:服务器上部署了多个tomcat,即垂直切分的Web站点,记忆多个Java微服务,突然收到运维的cpu异常告警. 步骤一:找到最耗cpu的进程 工具:top 方法: 执行top -c,显示进程 ...