东大 1535

   WenZhouTuHao is a very boring person(You will know who he is). There are n Building blocks. The blocks are number from 1 to n . For each i, the distance between the bottoms of Building blocks i and i+1 is exactly w . For each i,the height of Building blocks i is an integer bewteen 1 and H[i]. Tuhao want to take a single  piece of rope and use it to join the top ends of all Building blocks. Tuhao want to know what the maximized length he need to join the top ends of all Building blocks.

输入

     The first line contains two integer n,w(2<=n,w<=100)---the number of the Building blocks and the distance between the bottoms of Building blocks i and i+1.
     The next line contains n integers H[i] . (1<=H[i]<=100)

输出

 output the maximized length of the rop we need .Your return value must have a relative or an absolute error of less than 1e-3.

样例输入

3 2
3 3 3

样例输出

5.657

提示

 




//东北大学 1535

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<string>
#include <string.h>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<iomanip>
using namespace std;


double Dis(double w,int i,int j)  // 计算高度分别为i j ,相距为w的 distance
{
    return sqrt((i-j)*(i-j)+w*w);}

double l[101][101]={0};   //l[i][j] 代表前i栋楼,最后一栋楼为j高度,的最大值。
int h[101];
int n;
double w;
int main()
{
    cin>>n;
    cin>>w;
    for(int i=1;i<=n;i++)
         cin>>h[i];

    for(int i=0;i<101;i++)
       for(int j=0;j<101;j++)
          l[i][j]=0;
    for(int i=2;i<=n;i++)
       for(int j=1;j<=h[i];j++)
       {
           double maxx=0;
         for(int k=1;k<=h[i-1];k++){
            maxx=max(maxx,l[i-1][k]+Dis(w,k,j));
                                   }
         l[i][j]=maxx;

       }
    printf("%.3f\n",l[n][h[n]]);
    return 0;
}



















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值