| ||||||||||
| 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 | |||||||||
Re:晕..你每次return length[n]不一定是最大的那个噢...就先在length[1--n]中找到最大的returnIn Reply To:LIS but wrong code??? Posted by:mathsoft at 2006-07-24 19:38:51 > #include<stdio.h>
> #define N 1001
> int length[N],data[N];
> int LIS(int data[],int n)
> {
> int i,j;
> for(i=0;i<=n;i++)length[i]=1;
> for(i=1;i<=n-1;i++)
> for(j=i+1;j<=n;j++)
> if(data[j]>data[i])
> if(length[i]+1>length[j])
> length[j]=length[i]+1;
> return length[n];
> }
> int main()
> {
> int n;
> while(scanf("%d",&n)!=EOF)
> {
> for(int i=1;i<=n;i++)
> scanf("%d",&data[i]);
> printf("%d\n",LIS(data,n));
> //for(i=0;i<=n;i++)printf("%d ",length[i]);
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator