ZCMU 1037: I want you!

来源:互联网 发布:文华期货趋势指标源码 编辑:程序博客网 时间:2024/06/05 21:17

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

61 2 3 4 5 643 2 3 6

Sample Output

63

HINT

Source

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

HINT


第一次做的时候以为是简单的最长递增子序列,提交后直接就WA。仔细审题才发现,我们需要考虑一个特殊的数据,就是当a[i]为0时的处理,道理很简单:求不带不带0的最长递增子序列+数组里面0的个数=answer


#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[505],b[505];main (){    int n;    while(~scanf("%d",&n)){        memset(b,0,sizeof(b));        for(int i=0;i<n;i++)            scanf("%d",&a[i]);         b[0]=1;        int sum=0;        for(int i=1;i<n;i++){                if(!a[i]) sum++;            int max=0;            for(int j=0;j<i;j++)            if(a[i]&&a[j]<a[i]&&b[j]>max)            {                max=b[j];            }            b[i]=max+1;        }        sort(b,b+n);        printf("%d\n",b[n-1]+sum);    }}



Source
0 0
原创粉丝点击