题解:Tug of War(二维dp)

这篇博客探讨了如何使用二维动态规划方法解决在办公室野餐中进行拔河比赛时,如何将人员均匀分成两队的问题。通过输入人数和每个人的体重,目标是使两队的体重差异不超过1,并尽量平衡重量。算法通过遍历所有可能的组合,找到最接近总体重一半的分配方案。
摘要由CSDN通过智能技术生成

A tug of war is to be arranged at the local office picnic. For the tug of war, the picnickers must be divided into two teams. Each person must be on one team or the other; the number of people on the two teams must not differ by more than 1; the total weight of the people on each team should be as nearly equal as possible.

Input

The first line of input contains n the number of people at the picnic. n lines follow. The first line gives the weight of person 1; the second the weight of person 2; and so on. Each weight is an integer between 1 and 450. There are at most 100 people at the picnic.

Output

Your output will be a single line containing 2 numbers: the total weight of the people on one team, and the total weight of the people on the other team. If these numbers differ, give the lesser first.

    Sample Input
    3
    100
    90
    200


    Sample Output
    190 200

人数,体重接近,
bool:i人能否达到j体重

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值