# Monkey Party

Problem Description

Far away from our world, there is a banana forest. And many lovely monkeys live there. One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy Bananas Day. But the little monkeys don't know each other, so as the king, SDH must do something.

Now there are n monkeys sitting in a circle, and each monkey has a making friends time. Also, each monkey has two neighbor. SDH wants to introduce them to each other, and the rules are:

1.every time, he can only introduce one monkey and one of this monkey's neighbor.

2.if he introduce A and B, then every monkey A already knows will know every monkey B already knows, and the total time for this introducing is the sum of the making friends time of all the monkeys A and B already knows;

3.each little monkey knows himself;

In order to begin the party and eat bananas as soon as possible, SDH want to know the mininal time he needs on introducing.

Input

There is several test cases. In each case, the first line is n(1 ≤ n ≤ 1000), which is the number of monkeys. The next line contains n positive integers(less than 1000), means the making friends time(in order, the first one and the last one are neighbors). The input is end of file.

Output

For each case, you should print a line giving the mininal time SDH needs on introducing.

Sample Input

8

5 2 4 7 6 1 3 9

Sample Output

105

- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答

*1*条回答

#### 相关推荐

- 4年前回答 1 已采纳 Problem Description Far away from our world, there is a banana forest. And many lovely monkeys live there. One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy Bananas Day. But the little monkeys don't know each other, so as the king, SDH must do something. Now there are n monkeys sitting in a circle, and each monkey has a making friends time. Also, each monkey has two neighbor. SDH wants to introduce them to each other, and the rules are: 1.every time, he can only introduce one monkey and one of this monkey's neighbor. 2.if he introduce A and B, then every monkey A already knows will know every monkey B already knows, and the total time for this introducing is the sum of the making friends time of all the monkeys A and B already knows; 3.each little monkey knows himself; In order to begin the party and eat bananas as soon as possible, SDH want to know the mininal time he needs on introducing. Input There is several test cases. In each case, the first line is n(1 ≤ n ≤ 1000), which is the number of monkeys. The next line contains n positive integers(less than 1000), means the making friends time(in order, the first one and the last one are neighbors). The input is end of file. Output For each case, you should print a line giving the mininal time SDH needs on introducing. Sample Input 8 5 2 4 7 6 1 3 9 Sample Output 105
- 回答 1 已采纳 在提交小米应用市场的时候，检测出在红米3S、小米4C(安卓7.0)的时候报ANR， 但是在用真机运行的时候又没有发现问题，很是痛苦，希望有大牛可以帮我分析分析这个问题； 报错如下： 05-18 09:31:14.101 1334 1431 E ActivityManager: ANR in com.demo.code (com.demo.code/.SplashActivity) 05-18 09:31:14.101 1334 1431 E ActivityManager: PID: 5843 05-18 09:31:14.101 1334 1431 E ActivityManager: Reason: Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)
- 4年前回答 1 已采纳 Once in a forest, there lived N aggressive monkeys. At the beginning, they each does things in its own way and none of them knows each other. But monkeys can't avoid quarrelling, and it only happens between two monkeys who does not know each other. And when it happens, both the two monkeys will invite the strongest friend of them, and duel. Of course, after the duel, the two monkeys and all of their friends knows each other, and the quarrel above will no longer happens between these monkeys even if they have ever conflicted. Assume that every money has a strongness value, which will be reduced to only half of the original after a duel(that is, 10 will be reduced to 5 and 5 will be reduced to 2). And we also assume that every monkey knows himself. That is, when he is the strongest one in all of his friends, he himself will go to duel. Input There are several test cases, and each case consists of two parts. First part: The first line contains an integer N(N<=100,000), which indicates the number of monkeys. And then N lines follows. There is one number on each line, indicating the strongness value of ith monkey(<=32768). Second part: The first line contains an integer M(M<=100,000), which indicates there are M conflicts happened. And then M lines follows, each line of which contains two integers x and y, indicating that there is a conflict between the Xth monkey and Yth. Output For each of the conflict, output -1 if the two monkeys know each other, otherwise output the strongness value of the strongest monkey in all friends of them after the duel. Sample Input 5 20 16 10 10 4 5 2 3 3 4 3 5 4 5 1 5 Sample Output 8 5 5 -1 10
- 5年前回答 1 已采纳 Description Fly Monkey is a well-known program of the circus, which is performed by the beautiful and lovely monkey Pipi. In the program of Fly Monkey, there are two long steel wires in air. Pipi is initially located on one of the wires, and her objective is reaching another wire. Pipi must first crawl over the wire from her initial position by some distance, and then jump to some position of another wire. Since Pipi moves quite fast, the trace of her jumping can be considered as a straight line. To prevent from dangers, Pipi tends to shorten her jumping distance, while cannot crawl by more than distance d in advance to save the time. In this conditions, how long Pipi must jump at least? Input Input contains multiple test cases. Each test case contains 16 real numbers in one line, which are x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, xp, yp, zp, d. (x1, y1, z1)–(x2, y2, z2) are the coordinates of the two ends of the first wire, (x3, y3, z3)–(x4, y4, z4) are the coordinates of the two ends of the second wire, (xp, yp, zp) is the coordinate of the initial position of Pipi, d is the maximum distance Pipi can crawl. It is guaranteed that Pipi must locate on the first wire, and the lengths of the two wires are positive. But wires may intersect or even overlap. Output There is only one line for each test case, which contains a real number. Three digits after decimal point are preserved by rounding. Sample Input 0.0 0.0 0.0 4.0 4.0 0.0 4.0 0.0 1.0 0.0 4.0 1.0 2.0 2.0 0.0 10.0 Sample Output 1.000
- 回答 2 已采纳 Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food. The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked. Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks. Input The input file will contain one or more test cases. The first line of each test case contains an integer n, representing the number of different blocks in the following data set. The maximum value for n is 30. Each of the next n lines contains three integers representing the values xi, yi and zi. Input is terminated by a value of zero (0) for n. Output For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height". Sample Input 1 10 20 30 2 6 8 10 5 5 5 7 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 5 31 41 59 26 53 58 97 93 23 84 62 64 33 83 27 0 Sample Output Case 1: maximum height = 40 Case 2: maximum height = 21 Case 3: maximum height = 28 Case 4: maximum height = 342
- 回答 1 已采纳 Problem Description A crowd of little animals is visiting a mysterious laboratory – The Deep Lab of SYSU. “Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition project of Google and academia? Are you curious about what technology is behind those fantastic demos?” asks the director of the Deep Lab. “Deep learning, deep learning!” Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a piece of cake’. I won’t tell you a top secret that our lab has invented a Deep Monkey (深猴) with more advanced technology. And that guy is as smart as human!” “Nani ?!” Little Tiger doubts about that as he is the smartest kid in his kindergarten; even so, he is not as smart as human, “how can a monkey be smarter than me? I will challenge him.” To verify their research achievement, the researchers of the Deep Lab are going to host an intelligence test for Little Tiger and Deep Monkey. The test is composed of N binary choice questions. And different questions may have different scores according to their difficulties. One can get the corresponding score for a question if he chooses the correct answer; otherwise, he gets nothing. The overall score is counted as the sum of scores one gets from each question. The one with a larger overall score wins; tie happens when they get the same score. Little Tiger assumes that Deep Monkey will choose the answer randomly as he doesn’t believe the monkey is smart. Now, Little Tiger is wondering “what score should I get at least so that I will not lose in the contest with probability of at least P? ”. As little tiger is a really smart guy, he can evaluate the answer quickly. You, Deep Monkey, can you work it out? Show your power! Input The first line of input contains a single integer T (1 ≤ T ≤ 10) indicating the number of test cases. Then T test cases follow. Each test case is composed of two lines. The first line has two numbers N and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is a floating number with at most 3 digits after the decimal point, and is in the range of [0, 1]. The second line has N numbers separated by blanks, which are the scores of each question. The score of each questions is an integer and in the range of [1, 1000] Output For each test case, output only a single line with the answer. Sample Input 1 3 0.5 1 2 3 Sample Output 3
- 回答 1 已采纳 I have the below class in a 3rd party library which I am not supposed to modify. <?php class MyMailer { public function send() { $mail = new PHPMailer(); $mail->setFrom('from@example.com', 'Your Name'); $mail->addAddress('myfriend@example.net', 'My Friend'); $mail->Subject = 'First PHPMailer Message'; $mail->Body = 'Hi! This is my first e-mail sent through PHPMailer.'; $mail->Send(); } public function check(){ //code } } How can I override or hook the send() method or how can I override the entire class MyMailer with my own new class? The below link suggests to use runKit which is not bundled with PHP by default. So there is no guarantee that it's all available in all my servers. I learnt that this approach is called Monkey Patching. Redefine Class Methods or Class monkey patching in php https://github.com/antecedent/patchwork All the answers are very old and I wish if there are any new solution available.
- 回答 2 已采纳 先贴make错误信息： [b]$ make -f Makefile.ref cat: ../../dist/WINNT5.1_DBG.OBJ/nspr/Version: No such file or directory make -f Makefile.ref WINNT5.1_DBG.OBJ/js32.dll WINNT5.1_DBG.OBJ/js.exe cat: ../../dist/WINNT5.1_DBG.OBJ/nspr/Version: No such file or directory make[1]: Entering directory `/home/work/js/src' cl -FoWINNT5.1_DBG.OBJ/ -c -MD -Od -Zi -FdWINNT5.1_DBG.OBJ/jsapi.pdb -D_X86_=1 -DXP_WIN -DXP_WIN32 - DWIN32 -D_WINDOWS -D_WIN32 -DWINVER=0x500 -D_WIN32_WINNT=0x500 -nologo -W3 -DDEBUG -DDEBUG_zhongw -IWINNT5.1_DBG.OBJ -Op -DEXPORT_JS_API jsapi.c make[1]: cl: Command not found make[1]: *** [WINNT5.1_DBG.OBJ/jsapi.obj] Error 127 make[1]: Leaving directory `/home/work/js/src' make: *** [all] Error 2[/b] 1、没有用过make，如果现在要去看相关文档，太费时间，直接针对编译对象进行提问也许来得快些。 2、不知是不是SpiderMonkey不支持Cygwin？ 3、上面的信息如何解释？或者如何解决？ Cygwin和SpiderMonkey都是最新版本。 [b]问题补充：[/b] TO:lovewhzlq 你贴的那两个博文对我这个问题没有多大帮助，因为编译环境不一样，我的环境是Cygwin。谢谢你的回复。
- 5月前面向大海的编程的博客 只为做个笔记 #include<bits/stdc++.h> using namespace std; const int MAXN=1010*2; const int INF=0xffffffff;//小一点防止越界 int dp[MAXN][MAXN],w[MAXN],sum[MAXN],s[MAXN][MAXN],n;...
- Dream Flying Eagle的博客 Monkey Party（动态规划-区间dp-四边形不等式优化） judge：HDUOJ 3506 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) source：2010 ACM-ICPC Multi-University Training ...
- 娃娃酱斯密酱的博客 HDU-3506-Monkey Party 传送门 经典区间dp拓展。 在石子合并基础上化曲为直即可。 题目大意：围成一个圆形的一堆猴子要相互认识，问他们相互认识的最小代价。其中两猴子相识的代价等于他们各自相互认识的猴子的代价...
- accept_2333的博客 Far away from our world, ... One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy Bananas Day. But the little monkeys don’t know each other, so
- 我不是手机的博客 有n堆石子围成一个圆型，每堆石子数量分别为a1,a2…an(从a1到an围成一圈，an与a1相邻）现在要将这n堆石子合并成一堆，每次只能合并相邻的两堆，每次合并的得分是这两堆石子的数量之和，计算这n堆石子合并成一堆的...
- 电击公主就是我的lp的博客 原题目： Far away from our world, there is a banana forest. And many lovely monkeys live... One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy...
- weixin_34258782的博客 HDU - 3506 思路： 平行四边形不等式优化dp 这不就是石子归并（雾 代码： #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h>...#defin...
- Yuhan の Blog的博客 思路： 1.这题是经典区间dp问题“石子合并”的一个变型； 2.“石子合并”是没有围成环的情况，设dp[i][j]为将从i到j的石子合成一堆的最小花费（本题即是i到j所有猴子认识的花费的时间），则有递推dp[i][j]=min(dp[i...
- nobleman__的博客 Monkey Party Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1855 Accepted Submission(s): 821 Problem Description Far away from our wor...
- 默_silence的博客 Far away from our world, there is a banana forest. And many lovely monkeys live ... One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy Banan...
- minsst的博客 Monkey Party 传送门HDU-3506 题意：是让你每次把相邻两队猴子合为一队，并且其时间花费为两队的猴子数总和，问把所有猴子合为一队最小需要的时间。 思路：这应该是一个区间DP的题，但是这个题是一个环形区间DP问题...
- 想成神的小萌新的博客 Monkey PartyTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 4515 Accepted Submission(s): 1662 Problem Description Far away from our world, ...