SDAU 练习三 1019 学院设备平分问题

原创 2016年05月31日 23:03:47

Problem S

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 116   Accepted Submission(s) : 46
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.<br>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&lt;N&lt;1000) kinds of facilities (different value, different kinds).<br>
 

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.<br>A test case starting with a negative integer terminates input and this test case is not to be processed.<br>
 

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.<br>
 

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

Sample Output
20 10 40 40

简单题意:

       如今,我们都知道,计算机学院二是最大的部门。但是,也许你不知道曾经分成计算机学院计算机学院和软件学院在2002年。< br >二分裂绝对是一个大事件!与此同时,这是一件麻烦的事。所有设备必须平分。首先,所有设施评估,和两个设施被认为是相同的,如果他们有相同的值。假设有N(0 & lt;N<1000)类型的设施。

 

简单思路:

    这个是以前做的,思路有点遗忘,总的来说用一个数储存下来总价值,用一个累加数组记录n的值,再加上状态转移方程“dp[j]=max(dp[j],dp[j-a[i]]+a[i]);”就ok了。。

代码如下:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t,n,m,i,j,k,sum;
    int dp[100001];
    int a[100001];
    while(cin>>t&&t>=0)
    {
        memset(dp,0,sizeof(dp));
        sum=0;
        k=0;
        for(i=0;i<t;i++)
        {
            cin>>n>>m;
            sum+=n*m;
            for(j=0;j<m;j++)
            {
                a[k++]=n;
            }
        }
        for(i=0;i<k;i++)
        {
            for(j=sum/2;j>=a[i];j--)
            {
                dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
            }
        }
        cout<<sum-dp[sum/2]<<" "<<dp[sum/2]<<endl;
    }
    return 0;
}





版权声明:不经思考,不要拿走哦。。

相关文章推荐

SDAU练习三 1003 棋子跳跃问题

                         &#...

SDAU 练习三 1008 穿越大魔王的幽谷的问题

Problem H Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

SDAU 练习四1001 acm村庄建设最小长度问题

Problem A Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) There ar...

SDAU 练习四1002 acm 艾迪画墨水问题

Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

SDAU 练习三 1024 商人与项目

Problem X Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total...

SDAU 贪心专题 15 牛奶问题

1:问题描述 Problem Description The cows have purchased a yogurt factory that makes world-famous Yucky ...

SDAU 搜索专题 05 转弯问题

1:问题描述 Problem Description Mr. West bought a new car! So he is travelling around the city.One day ...

SDAU 贪心专题 13 盈利问题

1:问题描述 Problem Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug...

2016SDAU课程练习一1004 E

Problem E Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total S...

2016SDAU课程练习一Problem G

1题目编号:Problem G 2简单题意:(1)up一楼6s,down一楼4s,stop一楼5s。 (2)输入0时结束。3.解题思路形成过程:其一,由(2)知,需要对输入进行限...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)