牛客网暑期ACM多校训练营(第三场)---A.PACM Team
链接: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 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 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.
- 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
输入
- 2
- 1 0 2 1 10
- 1 0 2 1 21
- 1 0 2 1
输出
- 1
- 1
示例2
输入
- 1
- 2 1 1 0 31
- 1 0 2 1
输出
- 0
#include<bits/stdc++.h>
using namespace std;
const int maxn = 37;
int dp[maxn][maxn][maxn][maxn];
bool path[maxn][maxn][maxn][maxn][maxn];
int p[40], a[40], c[40], m[40], g[40];
int ans;
stack<int>s;
void solve(int i, int j, int k, int l, int o){
while(i && (j || k || l || o)){
if(path[i][j][k][l][o]){
ans++;
s.push(i-1);
j=j-p[i];
k=k-a[i];
l=l-c[i];
o=o-m[i];
}
i--;
}
}
int main() {
int n, P, A, C, M;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d%d%d%d%d", &p[i], &a[i], &c[i], &m[i], &g[i]);
}
scanf("%d%d%d%d", &P, &A, &C, &M);
memset(dp, 0, sizeof(dp));
memset(path, 0, sizeof(path));
for(int i = 1; i <= n; i++) {
for(int j = P; j >= p[i]; j--) {
for(int k = A; k >= a[i]; k--) {
for(int l = C; l >= c[i]; l--) {
for(int o = M; o >= m[i]; o--) {
//dp[j][k][l][o] = dp[j][k][l][o];
if(dp[j][k][l][o]<dp[j-p[i]][k-a[i]][l-c[i]][o-m[i]]+g[i]){
path[i][j][k][l][o]=1;
dp[j][k][l][o]=dp[j-p[i]][k-a[i]][l-c[i]][o-m[i]]+g[i];
}
}
}
}
}
}
ans = 0;
solve(n, P, A, C, M);
printf("%d\n", ans);
while(!s.empty()) {
cout << s.top() << " ";
s.pop();
}
cout << endl;
return 0;
}
牛客网暑期ACM多校训练营(第三场)---A.PACM Team的更多相关文章
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
- 牛客网暑期ACM多校训练营(第九场)D
链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...
- 牛客网暑期ACM多校训练营(第二场)B discount
链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...
- 2018牛客网暑期ACM多校训练营(第一场)D图同构,J
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...
- 牛客网暑期ACM多校训练营(第二场) I Car 思维
链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...
- 牛客网暑期ACM多校训练营(第二场) D money 思维
链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...
随机推荐
- 后端基于方法的权限控制--Spirng-Security
后端基于方法的权限控制--Spirng-Security 默认情况下, Spring Security 并不启用方法级的安全管控. 启用方法级的管控后, 可以针对不同的方法通过注解设置不同的访问条件: ...
- Spark 系列(三)—— 弹性式数据集RDDs
一.RDD简介 RDD 全称为 Resilient Distributed Datasets,是 Spark 最基本的数据抽象,它是只读的.分区记录的集合,支持并行操作,可以由外部数据集或其他 RDD ...
- Kubernetes Pod 驱逐详解
原文链接:Kubernetes Pod 驱逐详解 在 Kubernetes 中,Pod 使用的资源最重要的是 CPU.内存和磁盘 IO,这些资源可以被分为可压缩资源(CPU)和不可压缩资源(内存,磁盘 ...
- Re-Architecting the Video Gatekeeper(一)
原文 https://medium.com/netflix-techblog/re-architecting-the-video-gatekeeper-f7b0ac2f6b00 本文介绍了了内容配置工 ...
- Opengl_入门学习分享和记录_番外篇01(MacOS上如何在Xcode 开始编辑OpenGL)
写在前面的废话: 哈哈 ,我可真是勤勉呢,今天又来更新了,这篇文章需要大家接着昨天的番外篇00一起食用! 正文开始: 话不多说,先看代码. 这里主要全是使用的glfwwindowhint 这个函数,他 ...
- bootstrape select使用小结
看看上面的效果是bootstrape使用的效果.虽然不是很好看,但是符合bootstrape的风格.来看看普通的select的样式 bootstrape下的select和普通select在bootst ...
- 大白话5分钟带你走进人工智能-第32节集成学习之最通俗理解XGBoost原理和过程
目录 1.回顾: 1.1 有监督学习中的相关概念 1.2 回归树概念 1.3 树的优点 2.怎么训练模型: 2.1 案例引入 2.2 XGBoost目标函数求解 3.XGBoost中正则项的显式表达 ...
- AutoCAD C#二次开发
https://www.cnblogs.com/gisoracle/archive/2012/02/19/2357925.html using System; using System.Collect ...
- 解决 Nginx 代理Apex慢的问题
前不久用 Nginx 代理 Oracle 的 Apex 速度非常慢,我之前Nginx 配置如下: server{ listen 80; server_name localhost; client_ma ...
- SpringBoot进阶教程(六十)intellij idea project下建多个module搭建架构(上)
在 IntelliJ IDEA 中,没有类似于 Eclipse 工作空间(Workspace)的概念,而是提出了Project和Module这两个概念.多module有一个父maven工程,多个子工程 ...