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

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

61 2 3 4 5 643 2 3 6

Sample Output

63

HINT

Source

浙江中医药大学第六届程序设计竞赛

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

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
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;
}

你可能感兴趣的:(dp)