错误的贪了一下,然后D了两下就过了。注意是不上升和不下降。。不是上升和下降。。
1 #include <cstring> 2 #include <cstdio> 3 #include <string> 4 #include <iostream> 5 #include <algorithm> 6 #include <cmath> 7 #include <map> 8 using namespace std; 9 #define INF 100000000 10 int p[200001]; 11 int dp[200001]; 12 int o1[200001]; 13 int o2[200001]; 14 int main() 15 { 16 int a,b,i,n; 17 scanf("%d%d",&a,&b); 18 n = b - a + 1; 19 for(i = 1;i <= n;i ++) 20 scanf("%d",&p[i]); 21 o1[1] = o2[1] = 1; 22 for(i = 2;i <= n;i ++) 23 { 24 if(p[i] >= p[i-1]) 25 o1[i] = o1[i-1]; 26 else 27 o1[i] = i; 28 if(p[i] <= p[i-1]) 29 o2[i] = o2[i-1]; 30 else 31 o2[i] = i; 32 } 33 for(i = 1;i <= n;i ++) 34 { 35 dp[i] = min(dp[o1[i]-1],dp[o2[i]-1]) + 1; 36 } 37 printf("%d ",dp[n]); 38 return 0; 39 }