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 |
暴力O(n^2)程序#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n,mxl,ans,a[6000],f[6000],g[6000]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { bool flg=false; for(int j=i-1;j>=1;j--) { if(a[j]==a[i]){flg=true;break;} if(a[j]>a[i]) { if(f[j]+1>f[i]) { f[i]=f[j]+1; g[i]=g[j]; } else if(f[j]+1==f[i]) g[i]+=g[j]; } } if(!flg)f[i]=max(f[i],1),g[i]=max(g[i],1); mxl=max(mxl,f[i]); } for(int i=1;i<=n;i++) { if(f[i]==mxl)ans+=g[i]; } printf("%d %d",mxl,ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator