20150419武大邀请赛之网络赛 D - Sloth's Angry

Description
A forest is full of sloths, they are so eager for tree leaves and as a result, very angry.
We assume that the forest is a map of N * M grids, and each of the gird is an empty land or contains a big sloth. It’s guaranteed that the sequence of the sloth is a continuous segment from the leftmost column for every row. ( You may consider that the number of columns M is infinite ).

As a sloth lover, you want to feed all the sloths as quick as possible. Every second you may select a rectangle area of the grids which only contains sloths and feed all the sloths there.
What’s the minimum time required to meet all the sloths’ needs in the forest?

Input
First line of each case contains one numbers N.(1≤  n ≤ 1 000).

The following line contains N numbers Ai, each describing the length of continuous sloths sequence from the left most column in every row. ( 1 <= Ai <= 10^9 )

 

Output

Output the answer on a single line for each case.

 

Sample Input
4

3 4 5 5

 

Sample Output

3

 

Hint
The distributing situation of the sloths in the sample is as follow:

SSS

SSSS

SSSSS

SSSSS
 

And you can choose three rectangles to cover it.

 

 

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n,a[1003];
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        bool s[1003]={0};
        int ans=0;
        for(int i=0;i<n;i++){
                if(s[i]==0) {
                for(int j=i+1;j<n;j++){
                    if(a[j]<a[i]) {break;}
                    if(a[j]==a[i]) s[j]=1;
                }
                ans++;
            }
        }
        printf("%d\n",ans);
    }
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值