Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴力O(n^2)程序

Posted by liu_cheng_ao at 2016-10-06 14:02:23 on Problem 1952
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator