zoukankan      html  css  js  c++  java
  • 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 p

    i

    , a

    i

    , c

    i

    , m

    i

    , g

    i

     indicating that i-th team consists of p

    i

     physics experts, a

    i

     algorithm experts, c

    i

     coding experts, m

    i

     math experts, and will bring g

    i

     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 ≤ p

    i

    ,a

    i

    ,c

    i

    ,m

    i

    ,g

    i

     ≤ 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
    四维背包,滚动数组优化,bool类型记录路径即可。
    #include <bits/stdc++.h>
    #define maxn 38
    using namespace std;
    int f[maxn][maxn][maxn][maxn]={0};
    int a[maxn]={0},b[maxn]={0},c[maxn]={0},d[maxn]={0},val[maxn]={0};
    int used[maxn];
    bool s[maxn][maxn][maxn][maxn][maxn];
    int main()
    {
        int P,A,C,M,i,j,k,l,g,n;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d%d%d%d%d",&a[i],&b[i],&c[i],&d[i],&val[i]);
        }
        scanf("%d%d%d%d",&P,&A,&C,&M);
        for(i=1;i<=n;i++)
        {
            for(j=P;j>=a[i];j--)
            {
                for(k=A;k>=b[i];k--)
                {
                    for(l=C;l>=c[i];l--)
                    {
                        for(g=M;g>=d[i];g--)
                        {
                         if(f[j-a[i]][k-b[i]][l-c[i]][g-d[i]]+val[i]>f[j][k][l][g])
                         {
                             s[i][j][k][l][g]=true;
                             f[j][k][l][g]=f[j-a[i]][k-b[i]][l-c[i]][g-d[i]]+val[i];
                         }
                        }
                    }
                }
            }
        }
        int now=n;
        vector<int> ans;
        while(n>0)
        {
            if(s[n][P][A][C][M])
            {
                ans.push_back(n);
                P-=a[n];
                A-=b[n];
                C-=c[n];
                M-=d[n];
            }
            n--;
        }
        printf("%d
    ",ans.size());
        for(int i=ans.size()-1;i>=0;i--)
        {
            if(i!=ans.size()-1) printf(" ");
            printf("%d",ans[i]-1);
        }
        if (ans.size())
            printf("
    ");
        return 0;
    }
    

      

  • 相关阅读:
    兄弟连,一般人来不起,来的肯定不是一般人!
    50天之脱变,66期第一个项目感受。切记平常心
    2016十大影响事件
    为什么要写年终总结
    20161228阅读笔记
    为什么要认识牛人
    李笑来:演讲能力是我这一生有幸学到的最重要能力
    张辉:工作几年就应该给自己“清零”
    小马宋:目标决定方法~坚持目标而不是方法
    李笑来的财务自由法~把一份时间卖出很多份
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/9374268.html
Copyright © 2011-2022 走看看