编程介的小学生 2016-12-26 04:56 采纳率: 20.5%
浏览 1017
已采纳

Hotel

Description

Zebel, the tour coordinator, has reserved a limited number of hotel rooms for his clients. Rooms have different capacities and naturally, different prices. Zebel decides to find the least cost assignment of the tour participants to the available rooms. His strategy is to fill the rooms with appropriate collection of people to minimize the overall room cost, but he is facing some restrictions that no two people of different sex that are not married may stay in the same room, and if a room is assigned to a married couple, no other person may stay in that room. Note that it is not necessary to put a married couple in the same room. It is also possible that we do not fill a room to its capacity.

You are to write a program to help Zebel find a least cost assignment of the tour participants to the reserved hotel rooms.
Input

The only number in the first line is t, the number of test cases that follow. The first line of each test case contains four integer numbers, 0 ≤ m ≤ 500 the number of male tour participants, 0 ≤ f ≤ 500 the number of female tour participants, 0 ≤ r ≤ 500 the number of rooms reserved by Zebel, and c ≥ 0 which is the number of marriage relations between tour participants. Note that polygamy is not allowed in the tour; i.e. each participant is either single or has a unique mate.

The description of the reserved rooms comes on the following r lines. Each line describes a room, by two integer numbers 1 ≤ bi ≤ 5, and 1 ≤ pi ≤ 1000, which are the capacity and price of this room.
Output

For each test case in the input, output the minimum cost of assigning the rooms to the tour participants. If this is not possible, output the phrase "Impossible" instead.
Sample Input

2
2 1 3 1
3 5
2 10
2 4
1 1 1 0
1 4
Sample Output

9
Impossible

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-26 05:01
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan