POJ-2949 Word Rings(SPFA DFS实现 + 环上平均权值最大)

该博客讨论了一道ACM题目,涉及字符串接龙和平均值优化问题。通过将字符串转化为边和点的形式,寻找环状路径使得平均边权重最大化。通过G++与C++的运行对比,提出利用SPFA算法优化和二分查找策略来解决问题。
摘要由CSDN通过智能技术生成

Description

A word ring is a sequence of words where the last two letters of each word are the same as the first two letters of the next word (and the last two letters of the last word are the same as the first two letters of the first word). For example, the following sequence is a word ring:

intercommunicational
alkylbenzenesulfonate
tetraiodophenolphthalein

Your task is to write a program that, given a list of words, finds a word ring. You have to make the word ring as impressive as possible: the average length of the words in the ring has to be as large as possible. In the above example, the average length is (20 + 21 + 24)/3 ≈ 21.6666 , which makes it somewhat impressive. Note that each word can be used at most once in the ring, and the ring can consist of a single word.

Input

The input contains se
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值