1994Across the River

1994   Across the River

题目描述

n men and m women (1 <= n <= m <= 200) want to cross a river. There is only one boat on the river, and it can carry k (k >= 1) people at most at a time. So they have to design a strategy to cross the river, but the following rule must be obeyed. That is, at any time, either on the riverside or on the boat, there's no woman or the number of women is no less than the number of men. So you task is to design a strategy that take all the people across the river, and this strategy takes the least steps. (take some people from one side to the other side counts one step). If no such strategy exists, just output "Impossible".


输入格式:

The input consists of several test cases, each input consists of three integers n, m, k. The input is terminated by EOF.

输出格式:

For each test case, output the least steps if possible, or "Impossible" if there is no such strategy.

输入样例 复制
2 2 2
2 2 1
输出样例 复制
5
Impossible

说明

1
6
通过提交
时空限制10000ms/32mb
题目来源ZOJ Monthly, January 2005
评测方式在线评测
题目类型
难        度