Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 最大面积直方图动态规划C++;_C++_Algorithm_Histogram_Dynamic Programming_Brute Force - Fatal编程技术网

C++ 最大面积直方图动态规划C++;

C++ 最大面积直方图动态规划C++;,c++,algorithm,histogram,dynamic-programming,brute-force,C++,Algorithm,Histogram,Dynamic Programming,Brute Force,我试图得到直方图中的最大面积 我已经用蛮力算法做了,效果很好,但我想用动态规划 我不需要任何代码,我只想知道写它的想法,但使用动态编程 这是我的暴力代码。 请注意:建筑物数是柱状图中的列数 int getMaxArea(build building[], int NumOfBuildings) { int BuildingHeight = 0; //Height of Smallest Building of current Iteration. int Total_Build

我试图得到直方图中的最大面积

我已经用蛮力算法做了,效果很好,但我想用动态规划

我不需要任何代码,我只想知道写它的想法,但使用动态编程

这是我的暴力代码。 请注意:建筑物数是柱状图中的列数

int getMaxArea(build building[], int NumOfBuildings) {

    int BuildingHeight = 0; //Height of Smallest Building of current Iteration.
    int Total_BuildingLength = 0; // Total length of current buildings iteration
    int max_area = 0; // Maximum Area Calculated
    int CurrentArea; //Store Current Area

    int i = 0;
    while (i < NumOfBuildings)
    {
        int j = i;
        BuildingHeight = building[j].height;

        while (j < NumOfBuildings) //(J)Iterate to the the last building starting from each (i) building. 
        {
            if (BuildingHeight >= building[j].height){
                BuildingHeight = building[j].height; // At Every Iteration assign new Smallest height for area calculation

            }
            // Each Step calculates Area.
            Total_BuildingLength += building[j].length;
            CurrentArea = BuildingHeight * Total_BuildingLength;

            if (max_area < CurrentArea){
                max_area = CurrentArea;
            }

            j++;
        }
        //Reset Length
        Total_BuildingLength = 0;
        i++;
    }
    return max_area; 
}
int-getMaxArea(build building[],int-NumOfBuildings){
int BuildingHeight=0;//当前迭代中最小建筑的高度。
int Total_BuildingLength=0;//当前建筑迭代的总长度
int max_area=0;//计算的最大面积
int CurrentArea;//存储当前区域
int i=0;
而(i=建筑[j].高度){
Buildinghight=building[j].height;//在每次迭代中为面积计算指定新的最小高度
}
//每一步计算面积。
总建筑长度+=建筑[j]。长度;
CurrentArea=建筑高度*总建筑长度;
if(最大面积<当前面积){
最大面积=当前面积;
}
j++;
}
//重置长度
总建筑长度=0;
i++;
}
返回最大面积;
}

Hello,不幸的是,这里不是进行代码审查的地方(如果你是这样问的话)。否则,如果您的实现存在实际问题,请在您的问题中明确说明。我不需要代码,我只想得到这个区域,但使用动态编程。