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

1243 nouse to delete

Posted by tayu at 2005-08-10 09:40:36 on Problem 1243
#include <stdio.h>

int a[1000];
int b[1000];
int f[1001][1001];

void sort(int *b, int sum);
void process(int *a, int *b, int sum);

main()
{
    int i,j;
    int sum;
    while (scanf("%d", &sum)!=EOF)
    {
		for(i=0 ;i<sum; i++)
		{
			scanf("%d",a+i);
			*(b+i)=*(a+i);
		}
		for(i=0; i<sum; i++)
        {
           for(j=0; j<sum; j++)
           {
               f[i][j]=0;
           }
        }
		sort(b, sum);
		process(a, b, sum);
		/*scanf("%d", &sum);*/
    }       
    return 0;
}

void process(int *a,int *b, int sum)
{
    int i,j;
    for(i=0; i<sum; i++)
    {
        for(j=0; j<sum; j++)
        {
            if (a[i]==b[j])
            {
                f[i+1][j+1] = f[i][j] + 1;
            }
            else
            {
                f[i+1][j+1] = f[i][j+1]>f[i+1][j] ? f[i][j+1] : f[i+1][j];
            }
        }
    }
    printf("%d\n",f[sum][sum]);
}

void sort(int *b, int sum)
{
    int i,j;
    int tmp;
    for(i=0; i<sum-1; i++)
    {
        for(j=i+1; j<sum; j++)
        {
            if (*(b+i)>*(b+j))
            {
                tmp=*(b+i);
                *(b+i)=*(b+j);
                *(b+j)=tmp;
            }
        }
    }
    
}

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