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 pi
, ai
, ci
, mi
, gi
indicating that i-th team consists of pi
physics experts, ai
algorithm experts, ci
coding experts, mi
math experts, and will bring gi
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 ≤ pi
,ai
,ci
,mi
,gi
≤ 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
#includeusing 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*/