zoukankan      html  css  js  c++  java
  • hdu 1171 Big Event in HDU (01背包)




    Big Event in HDU

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 28453    Accepted Submission(s): 10014


    Problem Description
    Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
    The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
     

    Input
    Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
    A test case starting with a negative integer terminates input and this test case is not to be processed.
     

    Output
    For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
     

    Sample Input
    2 10 1 20 1 3 10 1 20 2 30 1 -1
     

    Sample Output
    20 10 40 40
     


    题意,软件学院与计算机学院分东西,尽可能的使两个学院分的一样多,结果计算机学院分得的要大于等于软件学院的价值.


    即在一个空间容量为总价值的一半的情况下,怎样能使这个空间装的价值最大,这个最大值必定是小于等于总价值的一半的,即为终于软件学院分得的价值.须要注意的是 t 的范围是大于等于0,而不是不等于-1


    code:

    <pre name="code" class="cpp">#include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdio>
    #include<algorithm>
    #include<string>
    #include<queue>
    #define max1(a,b) a>b?

    a:b using namespace std; int num[1008],w[1008]; int main() { int t; while(~scanf("%d",&t),t>=0) { int v=0; for(int i=0; i<t; i++) { scanf("%d%d",&w[i],&num[i]); v+=w[i]*num[i]; } int sum=v; v=v/2.0+0.4; int dp[200007]= {0}; for(int i=0; i<t; i++) { while(num[i]--) { for(int j=v; j>=w[i]; j--) dp[j]=max1(dp[j],dp[j-w[i]]+w[i]); } } //不必找最大值,由上文可知 // if(sum-dp[v]>dp[v]) printf("%d %d ",sum-dp[v],dp[v]); // else // printf("%d %d ",dp[v],sum-dp[v]); } }



    
    

  • 相关阅读:
    Linux内核网络协议栈优化总纲
    Java实现 蓝桥杯VIP 算法训练 连续正整数的和
    Java实现 蓝桥杯VIP 算法训练 连续正整数的和
    Java实现 蓝桥杯VIP 算法训练 寂寞的数
    Java实现 蓝桥杯VIP 算法训练 寂寞的数
    Java实现 蓝桥杯VIP 算法训练 学做菜
    Java实现 蓝桥杯VIP 算法训练 学做菜
    Java实现 蓝桥杯VIP 算法训练 判断字符位置
    Java实现 蓝桥杯VIP 算法训练 判断字符位置
    Java实现 蓝桥杯VIP 算法训练 链表数据求和操作
  • 原文地址:https://www.cnblogs.com/jhcelue/p/6743920.html
Copyright © 2011-2022 走看看