ZCMU-1037

1037: I want you!

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 179   Solved: 29
[ Submit][ Status][ Web Board]

Description

Given an array Ai(0<=i

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

Now , we want to know the maximum of ∑Bi(0<=i

Input

The input consists of multiple test cases。For each test case ,the first line contains one integer n (1

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页要算入里面b这个数组里面只有0或者1,其实就是这样的我们就考虑b为1的情况来算就行了,因为他要a[i]*b[i]
#include 
#include 
#include
using namespace std;
int main()
{
	int n,i,j,count1=0,sum,num;
    while(~scanf("%d",&n))
    {
        sum=0;
        count1=0;
        int a[1000]={0};
         int b[1000]={0};
        for(i=0;ib[i])
                    b[i]=b[j];//判断下标比i小的元素小于i的如果此刻上升序列把b[j]序列的长度给a[i]之后再继续,
                    //这里起到一个动态给的过程
            }
            if(a[i]!=0)
                b[i]++;
            if(b[i]>sum)
             sum=b[i];
        }
        printf("%d\n",sum+count1);
    }
    return 0;
}


你可能感兴趣的:(ACM)