poj 1836 動態規劃

2022-04-28 16:33:07 字數 808 閱讀 5957

題目大意

n個士兵排成一排,不是按照高度順序排列。現在想要從中去掉幾名士兵,從而使得隊伍中剩餘的士兵能夠看到這排最左邊或者最右邊的那個士兵,某士兵能夠看到最左邊(或最右邊)的士兵指這名士兵和最左邊(或最右邊)士兵之間沒有另外一名士兵的高度大於等於這名士兵。

題目分析

實現(c++)

#include#include#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

typedef long long ll;

double height[1005];

int dp_inc[1005]; //從最左邊到達i處,以i結尾的最長上公升子串行長度

int dp_dec[1005]; //從i到達最右邊,以i開頭的最長下降子串行長度

int solve(int n)

} }for (int i = n - 1; i >= 0; i--)

} }int result = 0;

for (int i = 0; i < n; i++)

} return result;

}int main()

int result = solve(n);

printf("%d\n", n - result);

return 0;

}

poj 1836 最長上公升 下降子串行

alignment 題意 輸入一串數字代表著一列排好隊的軍人的身高,現在要求從其中移走一些人,使得剩餘在隊伍中的任何乙個人都可以向左或者向右看到隊伍的頭。隊伍中身高並列最高的幾個人不會相互阻礙,但是其餘的身高相同的人會相互阻礙視線,求最少要移出多少人才能滿足要求。首先理解一下題意,拋開背景,題目要求...

POJ 1836(動規,上公升下降子串行問題)

poj 1836,動規問題,上公升下降子串行問題,和普通的上公升 下降子串行問題最大的不同 要考慮佇列中點乙個或兩個的情況 include using namespace std intmain left i 以i位元素結尾的最長上公升子串行 for int i 0 i for int j 0 j ...

poj 動態規劃 1141

dp練習的第三道題,依然花了我斷斷續續好幾個小時 有人說看到題目裡的 2.if s is a regular sequence,then s and s are both regular sequences.3.if a and b are regular sequences,then ab is ...