yoylee_web

十年生死两茫茫,写程序,到天亮。 万行代码,Bug何处藏。 纵使上线又怎样,朝令改,夕断肠。...

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

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;
}





阅读更多
版权声明:猿友们点点关注和右上角的手指,我们共同进步,协同发展呀,嘿嘿(-.-)。另外,博客中有不当之处,还请不吝指教。转载也请注明出处哈: https://blog.csdn.net/CSDN___LYY/article/details/51549977
个人分类: 动态规划
上一篇SDAU 练习三 1004 谦逊(卑微)数字
下一篇SDAU 练习三 1024 商人与项目
想对作者说点什么? 我来说一句

EXCEL自动填充平分库存的问题

2017年12月14日 17KB 下载

没有更多推荐了,返回首页

关闭
关闭