编程介的小学生 2017-07-31 06:03 采纳率: 20.5%
浏览 767
已采纳

Cross The River

Problem Description
Most of you may have played the game called crossing the river. This game is: a farmer carries a wolf, a sheep and a basket of grass to cross a river , but only one boat can be used . And everytime ,at most one thing and the farmer can take the boat to cross the river because only the farmer can use the boat . But if the farmer is not in, the wolf will eat the sheep ,the sheep will eat the grass . You are asked to help the farmer cross the river without losing anything . I think most of you can find the way.
But this time , the problem is more difficult . The farmer now takes more things, and some of them may eat the other thing if the farmer is not in . At the same time , the boat is becoming more bigger and it may be able to carry more things .You are asked to help the farmer to find a way to cross the river as soon as possible without losing anything.

Input
Each test case will contain three integers n(1=<n<=11) ,m(m<=100) and t (1=<t<=5). n stands for the number of things the farmer carries , m stands for the number of dangerous condition that some things may be eaten by others ,t stands for the number of things the boat can carry besides the farmer.
Then n line follows , stands for the name of the n things . Then name will only contains lowercase letters ,and the length will not exceed 20.
Then m line follows ,each line contains several things ,which means if these things stay together without the farmer,some thing will been eaten.

Output
For each case, output the least time the farmer needs to operate the boat in one line.If it’s impossible to cross the river without losing anything ,just output -1 in one line.

Sample Input
2 1 1
sheep
wolf
sheep wolf

Sample Output
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-08-15 21:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码