(中等) 背包 HOJ 1293 Prison Rearrangement
来源:互联网 发布:radan软件 编辑:程序博客网 时间:2024/05/16 07:29
Prison Rearrangement
Submitted : 62, Accepted : 36
In order to lower the risk of riots and escape attempts, the boards of two nearby prisons of equal prisoner capacity, have decided to rearrange their prisoners among themselves. They want to exchange half of the prisoners of one prison, for half of the prisoners of the other. However, from the archived information of the prisoners' crime history, they know that some pairs of prisoners are dangerous to keep in the same prison, and that is why they are separated today, i.e. for every such pair of prisoners, one prisoners serves time in the first prison, and the other in the second one. The boards agree on the importance of keeping these pairs split between the prisons, which makes their rearrangement task a bit tricky. In fact, they soon find out that sometimes it is impossible to fulfill their wish of swapping half of the prisoners. Whenever this is the case, they have to settle for exchanging as close to one half of the prisoners as possible.
Input
On the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing two non-negative integers m and r, 1 < m < 200 being the number of prisoners in each of the two prisons, and r the number of dangerous pairs among the prisoners. Then follow r lines each containing a pair xi yi of integers in the range 1 to m, which means that prisoner xi of the first prison must not be placed in the same prison as prisoner yi
of the second prison.
Output
For each test scenario, output one line containing the largest integer k <= m / 2 , such that it is possible to exchange k prisoners of the first prison for k prisoners of the second prison without getting two prisoners of any dangerous pair in the same prison.
Sample Input
3101 03 31 21 31 18 121 11 21 31 42 53 54 55 56 67 68 78 8
Sample Output
5003
- (中等) 背包 HOJ 1293 Prison Rearrangement
- 【poj 1636】Prison rearrangement dfs+01背包
- pku1636 Prison rearrangement
- POJ 1636 Prison rearrangement
- poj 1636 Prison rearrangement
- poj 1636 Prison rearrangement
- POJ 1636 Prison rearrangement
- POJ 1636 Prison rearrangement
- POJ 1636 Prison rearrangement
- poj 1636 Prison rearrangement
- POJ 1636 Prison rearrangement
- 监狱调整 POJ1636 Prison rearrangement 传递闭包FLoyd DFS 二维背包 动态规划DP
- 【poj 1636】Prison rearrangement dp
- POJ 1636 Prison rearrangement 笔记
- poj 1636 Prison rearrangement (监狱调整)
- poj 1634 Prison rearrangement
- poj 1634 Prison rearrangement
- 菜鸟学算法之POJ1636 Prison Rearrangement
- linux rm 命令详解
- (简单) 树形dp HOJ 2500 Party at Hali-Bula
- (中等) 状态压缩dp HOJ 2480 The best travel design
- (中等) 状态压缩dp HOJ 2193 Time to Graduate
- *(中等) dp HOJ 2133 Tourist
- (中等) 背包 HOJ 1293 Prison Rearrangement
- (中等) 动态规划+搜索 HOJ 2156 Colored stones
- openstack实时迁移
- 搜索 HOJ 1114 Frame Stacking
- 基础题 HOJ 1140 Expanding Fractions
- (简单)搜索 HOJ 1692 Choose Your Own Adventure
- Gentoo无线网卡安装之b43无线驱动篇(二)
- (博弈) HOJ 2939 Coin Question
- 搜索 HOJ 1749 Doggone Moles
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里