姑且算作贪心吧,从左往右遍历,对于每一个从点,如果它的那个高度没有被其他木板占据,就让它尽可能向右延伸,最后看有多少次这种伸展操作。可以利用像并查集一样的结构来储存每个点最多能延伸到多远。

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int to[50005],a[50005],y[500005];
 6 int main()
 7 {
 8     int n,w;
 9     while(scanf("%d%d",&n,&w)!=EOF)
10     {
11         int ans=0;
12         for(int i=0,tp;i<n;i++)
13         {
14             scanf("%d%d",&tp,&a[i]);
15             to[i]=i;
16         }
17         a[n]=0;to[n]=n;
18         for(int i=n-1;i>=0;i--)
19         {
20             while(a[i]!=0&&a[i]<=a[to[i]+1])
21                 to[i]=to[to[i]+1];
22         }
23         memset(y,-1,sizeof(y));
24         for(int i=0;i<n;i++)
25         {
26             if(a[i]&&y[a[i]]<i)
27                 ans++,y[a[i]]=to[i];
28         }
29         printf("%d\n",ans);
30     }
31     return 0;
32 }