当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2790:Safe Gambling

题目描述
All banks and other financial institutions want their money to earn other money. It is really simple: they invest in some assets (such as stocks), wait until their value grows, and then sell them with a high profit.

Due to the crisis, the stock exchange rates change too quickly, which caused the stocks to become too risky assets. Since large and creditable banks cannot afford so much risk, they have to search for other activities that bring similar profit but that are more predictable. Such as betting the money in casinos.

You were asked by a manager of one important bank (whose name has to be kept secret, since this is a highly confidential matter) to develop a computer program that would help them to "invest" their money into a new modern roulette, operated by Casino Vater Und Tochter (CVUT).

The roulette is an unusual one. Each pocket ("number") may have a different price that must be paid when that particular number is used in a bet. Moreover, any bet in this roulette must simultaneously cover only adjacent pockets. The price of such a bet is the sum of prices for individual pockets.

Bank managers made a decision that in every bet, one half of the pockets must be covered. They supposed that if two such bets are made, all pockets will be covered and there will be absolutely no risk of losing. But they did not realize that croupiers also have to earn some money. This is why the number zero was introduced into roulettes. Therefore, the total number of pockets is always odd and two bets are not enough to cover all of them (there would always be one pocket left).

To eliminate any risks, it was decided that two bets are not enough. In each game, three bets must be made instead of two, to cover all existing pockets. Your task is to compute the minimal price of such bets.

输入解释
The input contains description of several roulettes. Each roulette description consists of two lines. The first line contains a single positive odd integer N = 2 * K + 1 (3 ≤ N < 200000), the number of roulette pockets.

The second line contains N positive integers separated by a space, denoting the price of individual pockets, in the order they appear on the circumference of the wheel. The last pocket is supposed to neighbor with the first one. All prices will be between zero and 1000.

The last roulette description is followed by a line containing zero.
输出解释
For each roulette, output the price of the optimal set of bets. The set must have following properties:

1. It contains exactly three bets.

2. Each bet covers K neighboring pockets.

3. The bets together cover all roulette pockets (of course, some numbers may be covered twice).

4. The sum of prices of the bets is minimal among all such possible sets. The price of a bet is the sum of prices for individual pockets.
输入样例
5
1 2 3 4 5
9
1 2 3 4 5 6 7 8 9
0
输出样例
16
51
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 CTU Open 2008

源链接: HDU-2790

最后修改于 2020-10-25T22:56:47+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 32768/32768K(Java/Others)