A. Trip For Meal
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

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 cmeters.

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.

Examples
input
3
2
3
1
output
3
input
1
2
3
5
output
0
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.

每次走最短的距离就行了;

代码写的有点长;

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std; int n,d,b,c,a[][],ans; int main(){
scanf("%d",&n);
n--;
scanf("%d%d%d",&d,&b,&c);
a[][]=d;
a[][]=b;
a[][]=d;
a[][]=c;
a[][]=b;
a[][]=c;
int u=;
for(int i=;i<=n;i++){
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
if(u==){
if(a[u][]<a[u][]){
ans+=a[u][];
u=;
continue;
}else{
ans+=a[u][];
u=;
continue;
}
}
}
printf("%d",ans);
}

最新文章

  1. bootstrap使用心得及css模块化的初步尝试
  2. dmesg 的时间戳处理
  3. c++ primer 5th 练习3.43
  4. Zabbix配置文件详解之服务端zabbix_server
  5. SQL Server 2008 R2 开启允许远程连接
  6. Zabbix简介(第一章第一节)
  7. 用SSH连接SSH连接nitrous.io
  8. flush privileges是什么意思?
  9. Arduino 串口篇 Arduino发送二进制 send binary via RS232-to-USB to PC
  10. python绝技 — 侦听802.11 Probe请求
  11. 蓝桥杯PREV-11:横向打印二叉树
  12. 2017年总结的前端文章——CSS高级技巧汇总
  13. Linux时间子系统之二:Alarm Timer
  14. 使用bootstrap-select有时显示“Nothing selected”
  15. java中最常见的几种运行时异常,你get了吗?
  16. APP加急审核
  17. 吴裕雄 29-MySQL 处理重复数据
  18. 使用jquery的$.ajax向服务端传递中文,避免乱码的解决办法!
  19. Python: 类中为什么要定义__init__()方法
  20. 《深入浅出WPF》读书笔记

热门文章

  1. 【深入Java虚拟机】之八:Java垃圾收集机制
  2. MITNIK ATTACK
  3. Java中继承与多态
  4. 扫雷游戏制作过程(C#描述):第四节、菜单操作
  5. 201521123076 《Java程序设计》第8周学习总结
  6. 201521123078 《Java程序设计》第6周学习总结
  7. 201521123029《Java程序设计》第1周学习总结
  8. 201521145048《Java程序设计》第13周学习总结
  9. 201521123003《Java程序设计》第9周学习总结
  10. Java第十二周学习总结