当前位置:网站首页>HDU1171_Big Event in HDU【01背包】
HDU1171_Big Event in HDU【01背包】
2022-07-27 16:39:00 【51CTO】
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24321 Accepted Submission(s): 8562
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
Author
lcy
题目大意:有N种设备,每种设备有一个价值和数量。先要将这N种设备按总价值
尽可能的平均分给两个学院。若不能完全平均分,则第一个学院多分一点。
问,两个学院能各能分得多少价值的设备?
思路:每种设备都有一个数量和价值,可以把每一个设备都当做一件物品,比如第
一种设备有M件,价值为V则转换为有M件物品,价值都为V。这样就能转换成01
背包了。把总价值的一半当做背包容量。求最多能装多少价值的物品。因为在尽可
能平分的基础上第一个学院要多分一些。所以结果为第一学院分得sum-dp[sum/2],
第二学院分得dp[sum/2]。
边栏推荐
- Unity learning notes (realize the conveyor belt)
- 每日一题(02):倒置字符串
- 2022 preparation for autumn recruitment 10W word interview sketch PDF version, with operating system and computer network interview questions
- sql 字段类型转换
- Definition of graph traversal and depth first search and breadth first search (2)
- How to break the team with automated testing
- Selenium自动化测试面试题全家桶
- Using MATLAB to generate graphics for journals and conferences - plot
- 电磁场学习笔记-矢量分析和场论基础
- asp.net 的经验
猜你喜欢

What if idea successfully connects to the database without displaying the table

Opening and using Alibaba cloud object storage OSS

Idea optimization strategy

如何用自动化测试搞垮团队

「测试新手百科」5 分钟快速上手Pytest 自动化测试框架

大冤种们,新进测试行业,如何正确选择意向企业?

Sword finger offer17- print from 1 to the maximum n digits - Analog

转行软测&跳槽到新公司,工作怎样快速上手?

进行接口测试时,连接数据库,对数据源进行备份、还原、验证操作

自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
随机推荐
Express get/post/delete... Request
2022 preparation for autumn recruitment 10W word interview sketch PDF version, with operating system and computer network interview questions
The first entry-level operation of kettle (reading excel, outputting Excel)
Using vscode to build u-boot development environment
Analysis of Eureka server
PHP字符串操作
IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.
go-zero单体服务使用泛型简化注册Handler路由
Self control principle learning notes - system stability analysis (1) - BIBO stability and Routh criterion
Kettle separate and merge records
New system installation mysql+sqlyog
Mongodb learning notes (1) - install mongodb and its related configurations
Self control principle learning notes - system stability analysis (2) - loop analysis and Nyquist bode criterion
Unity display Kinect depth data
ipfs通过接口获得公钥、私钥,并加密存储。第一弹
Sword finger offer17- print from 1 to the maximum n digits - Analog
Webmagic+selenium+chromedriver+jdbc grabs data vertically.
Use fastjson JSON (simple and rough version)
浅谈基本的网络基本故障和问题排查
Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus