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
DescriptionGiven 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
- ZCMU 1037: I want you!
- I Want To Spend My Lifetime Loving You
- iTestin移动App云测试工具---I want you!
- I want to do that you feel proud of me.
- I Want
- If you want,you can!
- if you want, you can!
- tech blogs you want
- 给你的歌《I Want To Spend My Lifetime Loving You》
- What I want for you 奥巴马给女儿的信
- hdu 1214 圆桌会议 数论 How strong I want to love you again!
- I Want to Know
- I want to cry
- I Want to Know
- nothing I want
- i want way out
- I want eating
- I want a girlfriend
- cureftp 上传文件没有权限问题
- Memory Systems
- Gradle 1.12用户指南翻译——第六十章. 初始化脚本
- Mysql学习笔记十二——数据类型
- CSS部分特效英语
- ZCMU 1037: I want you!
- Linux操作系统学习_2
- (转)Java的反射机制
- (转)Java中的反射机制
- jquery ajax 操作
- 工作日志
- PageRank的简单实现(scala版)
- Flask应用部署
- 即拿即用-仿IOS风格的弹出框和对话框