zoukankan      html  css  js  c++  java
  • ELEVATOR 南邮NOJ 1996

    ELEVATOR

    时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
    总提交 : 93            测试通过 : 24 

    题目描述

    In the library of NUPT there is an elevator. The elevator can lift no more than W kg.
    And you know in NUPT the library is always crowded.
    Here are N people want to get into the elevator. Each people have two facts, the weight and IQ.
    I want you to find the minimum of the combined IQ of the people outside the elevator when the combined weight of the people in the elevator is no more than W. 
    For example: when W,n=200,4
            The weight of people are: 65 50 85 55
            The IQ of peole are:     46 18 70 21
    65+50+85+55=255>W, so the elevator can lift them all.
    We chose to lift the 1st,2nd,3rd people, the sum of weight is 200<=W and the sum of  IQ of people out of the elevator is 21.
    So you have to output 21.

    输入

    In the first line there is an integer T indicating there T test cases.
    In the first of each case, there are two integers W,n.W is the max weight of peole in the elevator, and there are n people.
    In the next line there are n integers wi. The ith integer is the ith people’s weight.
    In the next line there are n integers vi. The ith integer is the ith people’s IQ.

    输出

    For each case you only output one integer. The combined IQ of the people outside the elevator.

    样例输入

    2
    0 1
    1
    1
    200 4
    65 50 85 55
    46 18 70 21

    样例输出

    1
    21

    提示

    null

    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    using namespace std;
    int main()
    {
        int dp[101][1001],m,T,C,w[101],val[101],i,j;
         scanf("%d",&C);
         while(C--){
         int sum=0;  //累加器
         scanf("%d%d",&T,&m);
         for(i=1;i<=m;i++)
             scanf("%d",&w[i]);  //体重
         for(i=1;i<=m;i++)
         {
             scanf("%d",&val[i]); //IQ值
             sum+=val[i];
         }
        memset(dp,0,sizeof(dp));  //置零
        for(i=1;i<=m;i++)
        for(j=0;j<=T;j++)
        {
            if(j>=w[i])
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);//放还是不放的选择
            else
                dp[i][j]=dp[i-1][j];
        }
        printf("%d
    ",sum-dp[m][T]);
        }
        return 0;
    }      //01背包问题的另一种形式

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    洛谷【P1480】A/B Problem
    bzoj 2654 && bzoj 3675 总结
    关于三维莫队问题的一些思考和探究
    BZOJ 1179 抢掠计划atm (缩点+有向无环图DP)
    BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay)
    Codeforces 919D Substring (拓扑图DP)
    【学习笔记】有向无环图上的DP
    【学习笔记】求解简单递归式的一般方法
    BZOJ 3930 Luogu P3172 选数 (莫比乌斯反演)
    POJ 1061 BZOJ 1477 Luogu P1516 青蛙的约会 (扩展欧几里得算法)
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965591.html
Copyright © 2011-2022 走看看