给你 n 个数 arr[i],让你将这 n 个数分成 从小到大的顺序,看可以分成几块,当然,每个块中的可以排序。。。
样例解释:
3
1 2 3
可以分成 1 2 3三块,拍完许之后是从小到大的。。
解体思路:
将从 0 到 n-1 的每个dp值算出来,咋算呢,dp值就是从 i 到 n-1的最小值。。。
但是不要采用 两个 for 的算法容易超时,所以直接采用从后往前的算法,前边的每一个dp值分别跟 自己比,取最小的那一个。。
上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5+5;
const int mod = 1e9+7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
int arr[maxn];
int dp[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
MM(dp);
MM(arr);
for(int i=0; i<n; i++)
scanf("%d",&arr[i]);
dp[n-1] = arr[n-1];
for(int i=n-2; i>=0; i--)
{
dp[i] = arr[i];
dp[i] = min(dp[i], dp[i+1]);
}
int ans = 1, Max = -INF;
for(int i=0; i<n; i++)
{
Max = max(Max, arr[i]);
if(dp[i+1] >= Max)
ans++;
}
cout<<ans<<endl;
}
return 0;
}