牛客多校第三场 A—pacm team (4维背包加路径压缩)
链接:https://www.nowcoder.com/acm/contest/141/A
来源:牛客网 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 , 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 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 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. ≤ N ≤
≤ pi,ai,ci,mi,gi ≤
≤ P, A, C, M ≤
输出描述:
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 ). 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
输入 复制 输出 复制 示例2
输入 复制 输出 复制
一开始写了五维,内存超限了
36我们发现2的36次不会超ll
所以用状压去存路径
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
struct node
{
int a,b,c,d,v;
}p[37];
int dp[37][37][37][37];
ll path[37][37][37][37];
int main()
{
int n;
scanf("%d",&n);
memset(dp,0,sizeof(dp));
memset(path,0,sizeof(path));
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d%d",&p[i].a,&p[i].b,&p[i].c,&p[i].d,&p[i].v);
}
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
for(int i=0;i<n;i++)
{
for(int j=a;j>=0;j--)
for(int k=b;k>=0;k--)
for(int q=c;q>=0;q--)
for(int w=d;w>=0;w--)
{
if(p[i].a>j||p[i].b>k||p[i].c>q||p[i].d>w)
continue;
else if(dp[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]+p[i].v>dp[j][k][q][w])
{
dp[j][k][q][w]=dp[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]+p[i].v;
path[j][k][q][w]=path[j-p[i].a][k-p[i].b][q-p[i].c][w-p[i].d]|(1ll<<i);
}
}
}
//cout<<dp[a][b][c][d]<<endl;
//cout<<path[a][b][c][d]<<endl;
int f=0;
int p[1000];
for(int i=0;i<n;i++)
{
if(path[a][b][c][d]&(1ll<<i))
{
p[f++]=i;
}
}
cout<<f<<endl;
for(int i=0;i<f;i++)
{
if(i)printf(" ");
printf("%d",p[i]);
}
printf("\n"); return 0;
}
牛客多校第三场 A—pacm team (4维背包加路径压缩)的更多相关文章
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
- 牛客多校第三场-A-PACM Team-多维背包的01变种
题目我就不贴了...说不定被查到要GG... 题意就是我们需要在P,A,C,M四个属性的限制下,找到符合条件的最优解... 这样我们就需要按照0/1背包的思路,建立一个五维度数组dp[i][j][k] ...
- 牛客多校第三场 A- PACM Team 背包/记忆路径
https://www.nowcoder.com/acm/contest/141#question 一眼背包,用四维dp记录在A,B,C,D条件限制下可以获得的最大知识点,但是题目要求输出路径,在输入 ...
- 牛客网多校训练第三场 A - PACM Team(01背包变形 + 记录方案)
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai, ...
- 2018牛客多校第三场 C.Shuffle Cards
题意: 给出一段序列,每次将从第p个数开始的s个数移到最前面.求最终的序列是什么. 题解: Splay翻转模板题.存下板子. #include <bits/stdc++.h> using ...
- Removing Stones(2019年牛客多校第三场G+启发式分治)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 初始时有\(n\)堆石子,每堆石子的石子个数为\(a_i\),然后进行游戏. 游戏规则为你可以选择任意两堆石子,然后从这两堆中移除一个石子,最 ...
- 2019年牛客多校第三场 F题Planting Trees(单调队列)
题目链接 传送门 题意 给你一个\(n\times n\)的矩形,要你求出一个面积最大的矩形使得这个矩形内的最大值减最小值小于等于\(M\). 思路 单调队列滚动窗口. 比赛的时候我的想法是先枚举长度 ...
- 2019牛客多校第三场 F.Planting Trees
题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ...
随机推荐
- C++通过jsoncpp类库读写JSON文件-json用法详解
介绍: JSON 是常用的数据的一种格式,各个语言或多或少都会用的JSON格式. JSON是一个轻量级的数据定义格式,比起XML易学易用,而扩展功能不比XML差多少,用之进行数据交换是一个很好的选择. ...
- 【测试工程师面试】面试官热衷询问的N个问题
1. 数据库中左连接右连接的区别 2.JAVA中continue和break的区别 3.Linux中查看某一个进程并且杀死 1.数据库中多表连接,根据不同的表的某一个字段进行关联, 左连接是将左边表全 ...
- Spring boot @Scheduled(cron = "* * * * * *") cron表达式详解
//@Scheduled(cron = "0 0/15 * * * ?") //每15分钟触发一次 //@Scheduled(cron = "5/10 * * * * ? ...
- Java SE LinkedList的底层实现
关于实现链表的底层原理 链表便于增删,不便于查询 package com.littlepage.linkedList; /** * 基于底层实现LinkedList * @author Littlep ...
- SQL中的float类型的数据
问题1. 如何在SQL中默认的使用float类型的数据 SQL中想要通过计算的方式最快的得到一个float类型的数据,只需要运算的其中一个值后面加上小数点就ok. 比如 :9/2=4 但是 :9/2 ...
- 在nodejs中的集成虹软人脸识别
==虹软官网地址==http://www.arcsoft.com.cn 在官网注册账号,并且申请人脸识别激活码, 选择SDK版本和运行系统(windows/linux/android/ios) ,我们 ...
- Lua和C++交互 学习记录之八:C++类注册为Lua模块
主要内容转载自:子龙山人博客(强烈建议去子龙山人博客完全学习一遍) 部分内容查阅自:<Lua 5.3 参考手册>中文版 译者 云风 制作 Kavcc vs2013+lua-5.3.3 1 ...
- Codeforces 600 E - Lomsat gelral
E - Lomsat gelral 思路1: 树上启发式合并 代码: #include<bits/stdc++.h> using namespace std; #define fi fir ...
- webpack踩坑之路 (2)——图片的路径与打包
刚开始用webpack的同学很容易掉进图片打包这个坑里,比如打包出来的图片地址不对或者有的图片并不能打包进我们的目标文件夹里(bundle).下面我们就来分析下在webpack项目中图片的应用场景. ...
- docker安装成功启动失败
docker安装成功却启动失败,查看docker服务,systemctl status docker.service, 服务日志提示Failed to start Docker Application ...