zcmu1037

1037: I want you!

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 261   Solved: 64
[ 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

61 2 3 4 5 643 2 3 6

Sample Output

63

HINT

Source

注意a[i] = 0的情况此时b[i]可直接为1,实际上就是最长递增序列+0的个数,且0不计入序列中。

#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define pi acos(-1)
int a[305], dp[305];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		int sum = 0;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			if (!a[i]) {
				sum++;
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
				dp[i] = 0;
				if (a[i]) {
					for (int j = 0; j < i; ++j) {
						if (a[i] > a[j]) {
							dp[i] = max(dp[i], dp[j] + 1);
						}
					}
				}
			ans = max(dp[i],ans);
		}
		cout << sum + ans << endl;
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值