牛客多校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)或 ...
随机推荐
- BZOJ4390: [Usaco2015 dec]Max Flow
BZOJ4390: [Usaco2015 dec]Max Flow Description Farmer John has installed a new system of N−1 pipes to ...
- WordPress升级出现Briefly unavailable for scheduled maintenance. Check back in a minute.
WordPress升级出现Briefly unavailable for scheduled maintenance. Check back in a minute. 打开博客时提示: Brief ...
- maven-appfuse配备步骤
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qiaqia609/article/details/36231851 maven-appfuse配置步 ...
- gradlew tasks
D:\AndroidWorkSpace\Qi\LocalM>gradlew tasks > Configure project : AAAA > Configure project ...
- hibernate 一对多 级联 保存修改 删除
一对多,一端设置: <set name="TWorkorderHistories" inverse="true" cascade="all&qu ...
- <再看TCP/IP第一卷>关于链路层的知识细节及相关协议
在TCP/IP协议族中,链路层的主要有三个目的: (1)为IP模块发送和接受数据报 (2)为ARP模块发送ARP请求和接受ARP应答 (3)为RARP发送RARP请求和接受RARP应答 TCP/IP支 ...
- (5)表单Action后台验证
/day31/src/cn/itcast/web/struts2/user/UserAction.java package cn.itcast.web.struts2.user; import com ...
- 解决ini-parser解析ini文件中文乱码问题
rickyah/ini-parser 是一个.net 平台解析ini文件的库,当ini文件中含有中文字符时会乱码. 解决:将文件通过Editplus 等文本编辑工具保存为 utf-8 + bom 格式 ...
- FZU 2091 播放器 (栈)
记住:!!!栈用完之后,在下次使用的时候一定要初始化!!花费了我一上午的时间,最后还是某杰想出来的. 题意:实现一个音乐播放器的操作,有3种操作. 注意:一开始播放器会播放播放列表中的第一首歌,也就是 ...
- ES BM25 TF-IDF相似度算法设置——
Pluggable Similarity Algorithms Before we move on from relevance and scoring, we will finish this ch ...