链接: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;
}

最新文章

  1. mysql关联表的复制
  2. SQL优化----百万数据查询优化
  3. putpixel
  4. Android实现归属地查询功能
  5. 1011 最大公约数GCD
  6. [HTML]HTML框架IFrame下利用JS在主页面和子页面间传值
  7. 第 2章 数组和 ArrayLists
  8. ArcGIS Runtime for Android开发教程V2.0(2)开发环境配置
  9. poj 2451 Uyuw&#39;s Concert(半平面交)
  10. oracle的sql优化
  11. Hadoop YARN介绍
  12. Vijos 1004 伊甸园日历游戏 博弈
  13. Java 基本语法----变量
  14. plsql developer 恢复默认布局界面
  15. python源码书籍
  16. MongDB集群容灾方案步骤
  17. 微信小程序--家庭记账本开发--01
  18. Java基础之一
  19. pip无法正常使用卸载并重新安装
  20. PhoneGap 数据库操作

热门文章

  1. JavaSE之——并没有多维数组
  2. html的一些基本语法学习与实战
  3. HTML加载FLASH(*.swf文件)详解
  4. webgl(three.js)实现室内定位,楼宇bim、实时定位三维可视化解决方案
  5. c#小灶——自动类型转换和强制类型转换
  6. python+unittest框架第二天unittest之简单认识Test Suite:测试套件
  7. 【hdu 2544最短路】【Dijkstra算法模板题】
  8. .NET中使用WebService,以及和一般处理程序、类库的区别
  9. Python中的for else 和while else的用法
  10. JVM调优实战:G1中的to-space exhausted问题