博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客多校3 A-PACM Team(状压降维+路径背包)
阅读量:5356 次
发布时间:2019-06-15

本文共 4558 字,大约阅读时间需要 15 分钟。

PACM Team

链接:

来源:牛客网

时间限制: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 p
i physics experts, a
i algorithm experts, c
i coding experts, m
i 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 g
i 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.
示例1

输入

21 0 2 1 101 0 2 1 211 0 2 1

输出

11
示例2

输入

12 1 1 0 311 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 
using namespace std;typedef long long ll;const int MAX = 37;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=1;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=1;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-1); } } } } } } queue
q; i=n; while(i>0&&VA>=0&&VB>=0&&VC>=0&&VD>=0){ if(b[VA][VB][VC][VD]&(1ll<<(i-1))){ q.push(i-1); VA-=va[i]; VB-=vb[i]; VC-=vc[i]; VD-=vd[i]; } i--; } printf("%d\n",q.size()); int f=0; while(q.size()){ if(f==0) f=1; else printf(" "); printf("%d",q.front()); q.pop(); } printf("\n"); //printf("%d\n",dp[VA][VB][VC][VD]); return 0;}/*42 1 7 4 21 0 1 1 32 4 5 3 280 1 1 1 24 1 3 5*/

 

转载于:https://www.cnblogs.com/yzm10/p/9374264.html

你可能感兴趣的文章
linux的子进程调用exec( )系列函数
查看>>
MySQLdb & pymsql
查看>>
zju 2744 回文字符 hdu 1544
查看>>
【luogu P2298 Mzc和男家丁的游戏】 题解
查看>>
前端笔记-bom
查看>>
上海淮海中路上苹果旗舰店门口欲砸一台IMAC电脑维权
查看>>
Google透露Android Market恶意程序扫描服务
查看>>
给mysql数据库字段值拼接前缀或后缀。 concat()函数
查看>>
迷宫问题
查看>>
【FZSZ2017暑假提高组Day9】猜数游戏(number)
查看>>
泛型子类_属性类型_重写方法类型
查看>>
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
Code Snippet
查看>>
zoj 1232 Adventure of Super Mario
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>