牛客多校第三场 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 ...
随机推荐
- 【译】第23节---Fluent API - 实体映射
原文:http://www.entityframeworktutorial.net/code-first/configure-entity-mappings-using-fluent-api.aspx ...
- SAP月结操作讲解
SAP月结操作讲解 https://wenku.baidu.com/view/ac6fe45d312b3169a451a4b9.html 步聚 操作内容 事务码 是否必须 操作时间 月/年结 1 ...
- HDU 2426 Interesting Housing Problem(二分图最佳匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2426 题意:每n个学生和m个房间,现在要为每个学生安排一个房间居住,每个学生对于一些房间有一些满意度,如果满意度 ...
- Ajax - 发送请求原理
1,什么是ajax? Asynchronous JavaScript and XML(当然现在xml已经由json代替): 主要是用于前后台的交互(表单提交已经被废弃): 使用场景:前台获取数据.表单 ...
- vue--存储
storage 一个存储库,它支持具有相同 api 的 sessionStorage 和 localStorage 安装和用法: storage 的 API: set(key,val) 用key和va ...
- selenium打开chrome时,出现 "您使用的是不受支持的命令行标记:--ignore-certificate-errors""
from selenium import webdriveroptions = webdriver.ChromeOptions()options.add_experimental_option(&qu ...
- c++ cmakelist 详解
基本元素 首先cmaklist必须包括以下几个部分: #工程名 project(study_case) #cmake最低版本需求 cmake_minimum_required(VERSION 2.8. ...
- 使用http://start.spring.io/ 生成工程
今天学习spring-cloud,无意中发现一个spring提供的构建工程的页面,想记录下,发现有个博客写的很好就直接抄过来了. 原文链接: https://blog.csdn.net/u01050 ...
- TypeError: atlas.getSpriteFrame is not a function
1.资源结构如下: 2.在使用cc.loader.loadRes动态异步加载cc.SpriteAtlas资源时出现这个错误,代码如下: var self = this; var url = " ...
- Codeforces 797B - Odd sum
B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory l ...