编程介的小学生 2019-06-06 17:50 采纳率: 20.5%
浏览 154

农夫过河的问题怎么安排调度,用C语言的程序的编写的代码的过程的方式如何实现的

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?