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

莫名wa了

Posted by frustrated at 2017-07-08 13:50:58 on Problem 1952
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define MAXN 5500
using namespace std;
int n,a[MAXN],b[MAXN],c[MAXN],ans;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) {scanf("%d",&a[i]);c[i]=1;b[i]=1;}
    for(int i=1;i<n;i++)
    {
        for(int j=i-1;j>=0;j--)
        {
            if(a[j]>a[i]) 
            {
                if (b[j]>=b[i]) {c[i]=c[j];b[i]=b[j]+1;}
                else if(b[j]==b[i]-1) c[i]+=c[j];
            } 
            if(a[i]==a[j]) {if(b[i]==1) c[i]=0; break;}
        }
        ans=max(ans,b[i]);
    }
    int num=0;
    for(int i=0;i<n;i++) if(ans==b[i]) num+=c[i];
    printf("%d %d",ans,num);while(1);
}

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