【题目】
1037: I want you!
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 298 Solved: 76
[Submit][Status][Web Board]
Description
Given an array Ai(0<=i<n), its length is n; We want to find an another array Bi , which is 0 or 1,and its length is n too;
Besides, Ai and Bi meets the following conditions:
If neither A[i]*B[i] nor A[j]*B[j] equals to 0, then A[i]*B[i] < A[j]*B[j];(0<=i<j<n)
Now , we want to know the maximum of ∑Bi(0<=i<n) you can get.
Input
The input consists of multiple test cases。For each test case ,the first line contains one integer n (1<n<=300).Next line contains n integers.
Output
For each case, output the maximum of ∑Bi.
Sample Input
6
1 2 3 4 5 6
4
3 2 3 6
Sample Output
6
3
【题解】
题意:输出给定序列的最长上升子序列的长度加上所包含的0的个数.
【代码】
#include<bits/stdc++.h>
using namespace std;
main()
{
int n,a[305],b[305];
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int l=1,sum=0;b[1]=a[0];
for(int i=1;i<n;i++)
if(a[i]==0)
sum++;
else if(a[i]>b[l])
b[++l]=a[i];
else
{
int t=upper_bound(b+1,b+l+1,a[i])-b;
b[t]=a[i];
}
printf("%d\n",l+sum);
}
}