River crossing time limit: +Ms | Memory Limit:65535KB Difficulty:4
-
-
Describe
-
Afandi is herding N sheep across the expanses of grassland when he finds himself blocked by a river. A single raft are available for transportation.
Afandi knows that he must ride on the raft for all crossings, but adding sheep to the raft makes it traverse the river Mor E slowly.
When Afandi was on the raft alone, it can cross the river in M minutes when the I sheep was added, it takes Mi minutes long Er to cross the river than with i-1 sheep (i.e., total m+m1 minutes with one sheep, m+m1+m2 with, etc.).
Determine the minimum time it takes for Afandi to get all of the sheep across the river (including time returning to get M Ore sheep).
-
-
Input
-
On the first line
-
of the input was a single positive integer k, telling the number of the test cases to follow. 1≤k≤5 Each case contains:
* Line 1:one space-separated integers:n and M (1≤n≤1000, 1≤m≤500).
* Lines 2..n+1:line i+1 contains a single integer:mi (1≤mi≤1000)
-
-
Output
-
-
for each test case, output a line with the minimum time it takes for Afandi to get all of the sheep across the river .
-
-
Sample input
-
-
2
-
-
2 Ten
-
-
3
-
-
5
-
-
5 10
-
-
3
-
-
4
-
-
6
-
-
100
-
-
1
-
-
Sample output
-
-
18
-
-
50
-
-
Source
-
-
sixth session of Henan Province Program design Competition
Test instructions: There are 1 people and n sheep to cross the river. It takes a man to cross the river alone to spend time with M, and take a sheep across the river time M+m1, with two
It takes time m+m1+m2 the sheep to cross the river ... Give N, M and Mi, and ask how much time it takes for all n sheep to cross the river at least.
Idea: Dp[i] represents the shortest time a person and I have spent crossing the river, first dp[0] = m, dp[i] = dp[i-1] + times, later more
, dp[i] = min (Dp[i],dp[i-j] + M + dp[j]), J loops from 1 to i-1, that is, I have a sheep divided into two stages to transport, only demand out
Two stages of the and, then add the time that people return from the other side, with Dp[i] to compare, take the minimum value.
AC Code:
Nyoj-716-river Crossing--sixth session of Henan Province Program Design competition (Simple dp!! )