链接: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的更多相关文章

  1. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  2. 牛客网 暑期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 ,问你 ...

  3. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  4. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  5. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

  6. 牛客网暑期ACM多校训练营(第九场)D

    链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...

  7. 牛客网暑期ACM多校训练营(第二场)B discount

    链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...

  8. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  9. 牛客网暑期ACM多校训练营(第二场) I Car 思维

    链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...

  10. 牛客网暑期ACM多校训练营(第二场) D money 思维

    链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...

随机推荐

  1. ABP实现EF执行SQL(增删改查)解决方案

    前言 一般情况下,使用EF中的语法可以帮助我们完成绝大部分业务,但是也有特殊的情况需要直接执行的Sql语句.比如,我们的业务过于复杂繁琐,或是有些业务使用EF操作时比较复杂,但是使用的Sql时会很简单 ...

  2. SpringBoot-Admin的使用

    [**前情提要**]Spring Boot Actuator 提供了对单个 Spring Boot 应用的监控,信息包含应用状态.内存.线程.堆栈等,比较全面的监控了 Spring Boot 应用的整 ...

  3. 63342 接口 奇遇 IDEA

    今天遇到一件很奇怪的事情,本来是想做一些手机页面看看效果,用IDEA 打搭建了一个静态页面网站,可是手机死活就是访问不了,网上的配置方法试过也没有用,其中包括这篇很详细博客: http://fanni ...

  4. SpringBoot学习系列之一(反射)

    最近在学习SpringBoot的知识,动起手来学习的时候才发现SpringBoot项目采用了大量的反射机制,晕,作为一个应届毕业生,以前学习反射的时候给我的感觉就是,这个到底用来干嘛的,好像没啥用啊, ...

  5. 记一次mysql数据库失而复得过程

    背景: 由于是自己买的vps搭建的博客,用的是军哥的一键lnmp源码编译安装的,文章也就几篇,对备份并不太重视,想着等服务器快到期的时候备份一下不就行了. 后来在该服务器上测试lnmp分别编译编译安装 ...

  6. 如何将自己的代码发布到Maven中央仓库?

    去年在公司做工作流相关业务时,当时使用flowable做引擎,中途涉及到一些业务上的需求,自己整理了一些代码,考虑到开源精神,当时就想着将于公司业务无关的代码抽离出来,放到Maven中央仓库中,以供别 ...

  7. windows的磁盘操作之七——获取当前所有的物理磁盘号 加备注

     windows的磁盘操作之七--获取当前所有的物理磁盘号 2011-07-28 17:47:56 标签:windows API DeviceIoControl 物理磁盘 驱动器号 原创作品,允许转载 ...

  8. input 上传图片

    <!--多图上传--><input name="image_mortgage_property[]" type="file" multiple ...

  9. tf.control_dependencies

    tf.control_dependencies()是用来控制计算流图的,给图中的某些节点指定计算的顺序. 原型: tf.control_dependencies(self, control_input ...

  10. Codeforces 1009E

    题意略. 思路: 比如现在n = 11.那么我们观察a[1.....n]的出现次数: a[1]:2 ^ 10 + 10 * 2 ^ 9 a[2]:2 ^ 9 + 9 * 2 ^ 8 a[3]:2 ^ ...