牛客多校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)或 ...
随机推荐
- Smarty入门学习
--------------------------------- 安装和设置 --------------------------------- require('../Smarty/Smarty. ...
- 利用socket.io实现多人聊天室(基于Nodejs)
socket.io简单介绍 在Html5中存在着这种一个新特性.引入了websocket,关于websocket的内部实现原理能够看这篇文章.这篇文章讲述了websocket无到有,依据协议,分析数据 ...
- angularJs-HelloWorld
AngularJS使用了不同的方法,它尝试去补足HTML本身在构建应用方面的缺陷.AngularJS通过使用我们称为标识符(directives)的结构,让浏览器能够识别新的语法. 1使用双大括号{{ ...
- java多线程系列 JUC锁01 框架
转载 http://www.cnblogs.com/skywang12345/p/3496098.html 参考 https://www.cnblogs.com/leesf456/p/5453091. ...
- :style动态设置属性
前段时间做页面时需要动态设置背景图片,每一种框架都会遇见类似的需求,特记录下来,以免不时之需: <!DOCTYPE html> <html> <head> < ...
- EASYARM-IMX283 nfs启动内核和根文件系统
EASYARM-IMX283(以下简称IMX283)默认采用从nand flash启动,但是在开发过程中因为要频繁的替换内核,我们更倾向于从nfs启动. 先看看IMX283中uboot中默认采用的启动 ...
- POJ3450 Corporate Identity —— 后缀数组 最长公共子序列
题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536 ...
- Contiki Timer & Stimer 模块
一.Timer API struct timer { clock_time_t start; clock_time_t interval; }; CCIF void timer_set(struct ...
- 学习c语言的第14天
#include <stdio.h> #include <string.h> struct student { int age; char sex; char name[100 ...
- zabbix api支持的数据类型
bool flag integer float string timestamp array object query countOutput editable excludeSearch filte ...