C
1 #include <bits/stdc++.h>
2 using namespace std;
3 const int MAX = 200+10;
4 int H[MAX];
5 double dp[MAX][MAX];
6 double get_dis(int a,int b) {
7 return sqrt((double)a*(double)a+(double)b*(double)b);
8 }
9 int main() {
10 freopen("in1.txt","r",stdin);
11 freopen("out1.txt","w",stdout);
12 int n,w;
13 while(scanf("%d %d",&n,&w)==2) {
14 for(int i=0;i<n;i++) {
15 scanf("%d",&H[i]);
16 }
17 memset(dp,0,sizeof(dp));
18 for(int i=1;i<n;i++) {
19 for(int j=1;j<=H[i];j++) {
20 for(int k=1;k<=H[i-1];k++) {
21 dp[i][j]=max(dp[i][j],dp[i-1][k]+get_dis(w,abs(k-j)));
22 }
23 }
24 }
25 double res=-1;
26 for(int i=1;i<=H[n-1];i++) {
27 res=max(res,dp[n-1][i]);
28 }
29 printf("%.3lf\n",res);
30 }
31 }
2 using namespace std;
3 const int MAX = 200+10;
4 int H[MAX];
5 double dp[MAX][MAX];
6 double get_dis(int a,int b) {
7 return sqrt((double)a*(double)a+(double)b*(double)b);
8 }
9 int main() {
10 freopen("in1.txt","r",stdin);
11 freopen("out1.txt","w",stdout);
12 int n,w;
13 while(scanf("%d %d",&n,&w)==2) {
14 for(int i=0;i<n;i++) {
15 scanf("%d",&H[i]);
16 }
17 memset(dp,0,sizeof(dp));
18 for(int i=1;i<n;i++) {
19 for(int j=1;j<=H[i];j++) {
20 for(int k=1;k<=H[i-1];k++) {
21 dp[i][j]=max(dp[i][j],dp[i-1][k]+get_dis(w,abs(k-j)));
22 }
23 }
24 }
25 double res=-1;
26 for(int i=1;i<=H[n-1];i++) {
27 res=max(res,dp[n-1][i]);
28 }
29 printf("%.3lf\n",res);
30 }
31 }