void PrintHistogramMolecules( std::ostream *out, vui Histogram, unsigned int Stop, unsigned int Start, unsigned int Step, int BarLength, unsigned int NumBins, std::string CC ) { double Scale; unsigned int Max = 0; if (Step == 0) // That does not make sense, abort! { std::cerr << "Step should be greater than zero (0)!" << "\n"; return; } // Find Max of Histogram if (Histogram.size() > 0 ) { for (unsigned int i = Start; i <= Stop; i += Step) if (Histogram[i] > Max) { Max = Histogram[i]; } } else { Max = 0; } // Define 'Scale' so the the maximum of the histogram will have a length // of 'BarLength' Scale = double(Max)/double(BarLength); // Using uniformStop to make it easy to aggregate // many TraceHBond output files unsigned int uniformStop; if ( NumBins > 0 ) uniformStop = Step*NumBins + Start - (unsigned int)1; else uniformStop = Stop; for (unsigned int i = Start; i <= uniformStop; i += Step ) { *out << CC.c_str() << " "; *out << std::setw(4) << i << " | "; if ( i >= Histogram.size() ) { // If uniformStop brings us past the size of Histogram, // show zeros. *out << std::setw(4) << 0 << "|"; } else { *out << std::setw(4) << Histogram[i] << "|"; for (int j = 0; j < Round(Histogram[i]/Scale); j++) *out << "*"; } *out << "\n"; } }
int main() { unsigned int N; cin >> N; for (ui i = 0; i < N; i++) { ui height; cin >> height; heights.push_back(height); } //sort(ALL(heights), std::greater<int>()); ui max = 0; for (ui i = 0; i < heights.size(); i++) { ui path = dfs(i, 0); if (path > max) max= path; } cout << max << endl; /* cout << N << endl; for (auto x : heights) cout << x << "-"; cout << endl; */ return 0; }
ui dfs(int curr, ui len) { //cout << heights[curr] << "-"; //cout << curr << " --- " << len << endl; ui a = 0; ui b = 0; ui c = 0; ui d = 0; if (curr - 2 >= 0) { if (heights[curr] > heights[curr - 2]) { a = dfs(curr - 2, len + 1); } } if (curr - 1 >= 0) { if (heights[curr] > heights[curr - 1]) { b = dfs(curr - 1, len + 1); } } if (curr + 1 < heights.size()) { if (heights[curr] > heights[curr + 1]) { c = dfs(curr + 1, len + 1); } } if (curr + 2 < heights.size()) { if (heights[curr] > heights[curr + 2]) { d = dfs(curr + 2, len + 1); } } ui currMax = max(max(max(a, b), max(c, d)), len); //if (currMax == len) // cout << "X" << endl; return currMax; }