1037: I want you!
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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;
}