A. Trip For Meal

Codeforces
IDCF876A
Time1000ms
Memory512MB
Difficulty
math
English · Original
Chinese · Translation
Formal · Original
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is _a_ meters, between Rabbit's and Eeyore's house is _b_ meters, between Owl's and Eeyore's house is _c_ meters. For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal _n_ times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store). Winnie-the-Pooh does not like physical activity. He wants to have a meal _n_ times, traveling minimum possible distance. Help him to find this distance. ## Input First line contains an integer _n_ (1 ≤ _n_ ≤ 100) — number of visits. Second line contains an integer _a_ (1 ≤ _a_ ≤ 100) — distance between Rabbit's and Owl's houses. Third line contains an integer _b_ (1 ≤ _b_ ≤ 100) — distance between Rabbit's and Eeyore's houses. Fourth line contains an integer _c_ (1 ≤ _c_ ≤ 100) — distance between Owl's and Eeyore's houses. ## Output Output one number — minimum distance in meters Winnie must go through to have a meal _n_ times. [samples] ## Note In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3. In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
小熊维尼非常喜欢蜂蜜!因此他决定去拜访他的朋友们。维尼有三位最好的朋友:兔子、猫头鹰和小驴,他们各自住在自己的房子里。每两栋房子之间都有蜿蜒的小路连接。兔子和猫头鹰家之间的路径长度为 $a$ 米,兔子和小驴家之间的路径长度为 $b$ 米,猫头鹰和小驴家之间的路径长度为 $c$ 米。 为了享受生活并唱欢快的歌曲,维尼每天需要进食 $n$ 次。现在他正在兔子的家里,并且已经完成了第一次进食。每次当维尼在某个朋友的家中时,那里的蜂蜜供应即将耗尽,他就会离开这所房子。如果他还没有完成规定的进食次数,他会从当前房子出来,前往另外两位朋友中的一个。为此,他选择两条相邻路径中的一条,前往另一端的房子并拜访那位朋友。你可以假设,当维尼在某位朋友家中进食时,其他朋友家中的蜂蜜供应会恢复(很可能他们去补货了)。 维尼不喜欢体力活动。他希望在总共进食 $n$ 次的前提下,行走的总距离最小。请帮助他计算这个最小距离。 第一行包含一个整数 $n$ ($1 ≤ n ≤ 100$) —— 进食次数。 第二行包含一个整数 $a$ ($1 ≤ a ≤ 100$) —— 兔子与猫头鹰家之间的距离。 第三行包含一个整数 $b$ ($1 ≤ b ≤ 100$) —— 兔子与小驴家之间的距离。 第四行包含一个整数 $c$ ($1 ≤ c ≤ 100$) —— 猫头鹰与小驴家之间的距离。 请输出一个数字 —— 维尼为了完成 $n$ 次进食所需行走的最小距离(单位:米)。 在第一个测试用例中,维尼的最优路径如下:首先在兔子家进食,然后去猫头鹰家,再前往小驴家。因此他走过的距离为 $2 + 1 = 3$。 在第二个测试用例中,维尼只在兔子家进食一次就完成了目标,因此他不需要走任何路。 ## Input 第一行包含一个整数 $n$ ($1 ≤ n ≤ 100$) —— 进食次数。第二行包含一个整数 $a$ ($1 ≤ a ≤ 100$) —— 兔子与猫头鹰家之间的距离。第三行包含一个整数 $b$ ($1 ≤ b ≤ 100$) —— 兔子与小驴家之间的距离。第四行包含一个整数 $c$ ($1 ≤ c ≤ 100$) —— 猫头鹰与小驴家之间的距离。 ## Output 输出一个数字 —— 维尼为了完成 $n$ 次进食所需行走的最小距离(单位:米)。 [samples] ## Note 在第一个测试用例中,维尼的最优路径如下:首先在兔子家进食,然后去猫头鹰家,再前往小驴家。因此他走过的距离为 $2 + 1 = 3$。在第二个测试用例中,维尼只在兔子家进食一次就完成了目标,因此他不需要走任何路。
**Definitions** Let $ n \in \mathbb{Z} $ be the number of meals (visits). Let $ a, b, c \in \mathbb{Z} $ be the distances between the houses: - $ a $: Rabbit ↔ Owl - $ b $: Rabbit ↔ Eeyore - $ c $: Owl ↔ Eeyore Let the houses be labeled: - $ R $: Rabbit - $ O $: Owl - $ E $: Eeyore Winnie starts at $ R $ for the first meal. **Constraints** $ 1 \leq n \leq 100 $, $ 1 \leq a, b, c \leq 100 $ **Objective** Find the minimum total travel distance to complete $ n $ meals, starting at $ R $, such that after each meal, Winnie moves to a different house (no immediate return), and the path between houses has length as defined. Let $ d(i) $ be the minimum total distance to complete $ i $ meals ending at a specific house. Define: - $ d_R(i) $: min distance after $ i $ meals, ending at $ R $ - $ d_O(i) $: min distance after $ i $ meals, ending at $ O $ - $ d_E(i) $: min distance after $ i $ meals, ending at $ E $ **Initial condition** $ d_R(1) = 0 $, $ d_O(1) = \infty $, $ d_E(1) = \infty $ **Transitions for $ i \geq 2 $:** $$ \begin{aligned} d_R(i) &= \min(d_O(i-1) + a,\ d_E(i-1) + b) \\ d_O(i) &= \min(d_R(i-1) + a,\ d_E(i-1) + c) \\ d_E(i) &= \min(d_R(i-1) + b,\ d_O(i-1) + c) \end{aligned} $$ **Output** $ \min(d_R(n), d_O(n), d_E(n)) $
Samples
Input #1
3
2
3
1
Output #1
3
Input #2
1
2
3
5
Output #2
0
API Response (JSON)
{
  "problem": {
    "name": "A. Trip For Meal",
    "description": {
      "content": "Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding pa",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF876A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding pa...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "小熊维尼非常喜欢蜂蜜!因此他决定去拜访他的朋友们。维尼有三位最好的朋友:兔子、猫头鹰和小驴,他们各自住在自己的房子里。每两栋房子之间都有蜿蜒的小路连接。兔子和猫头鹰家之间的路径长度为 $a$ 米,兔子和小驴家之间的路径长度为 $b$ 米,猫头鹰和小驴家之间的路径长度为 $c$ 米。\n\n为了享受生活并唱欢快的歌曲,维尼每天需要进食 $n$ 次。现在他正在兔子的家里,并且已经完成了第一次进食。每次当维...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of meals (visits).  \nLet $ a, b, c \\in \\mathbb{Z} $ be the distances between the houses:  \n- $ a $: Rabbit ↔ Owl  \n- $ b $: Rabbit ↔ Eeyore  \n-...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments