Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求救!为什么总是WA?#include<iostream.h> int main() { int n,i,j,max,sum,dmax; cin>>n; int *a=new int [n+1]; int *b=new int [n+1]; int *c=new int [n+1]; for(i=0;i<n;i++) c[i]=0; for(i=0;i<n;i++) cin>>a[i]; max=0; for(i=0;i<n;i++) { b[i]=1; for(j=0;j<i;j++) { if(a[j]>a[i]) if(b[j]+1>b[i]) b[i]=b[j]+1; if(b[i]>max) max=b[i]; } dmax=-1; for(j=0;j<i;j++) { if(a[j]>a[i]&&b[i]==b[j]+1) if(c[j]==0) { if(a[j]!=dmax) { c[i]++; dmax=a[j]; } } else { if(a[j]!=dmax) { c[i]+=c[j]; dmax=a[j]; } } } } int count=0; sum=0; int dm=-1; for(i=0;i<n;i++) { if(b[i]==max&&a[i]!=dm) { sum+=c[i]; dm=a[i]; } } if(n==1) { max=sum=1; cout<<max<<" "<<sum<<endl; } else{ cout<<max<<" "; dm=-1; if(sum==0) { for(i=0;i<n;i++) { if(a[i]!=dm) { sum++; dm=a[i]; } } cout<<sum<<endl; } else cout<<sum<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator