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

DP,贴代码,飘过~~

Posted by yingxiang720 at 2011-03-26 00:54:02 on Problem 2533
#include <iostream>
using namespace std;

double h[1100];
int dp[1100];

int cmax(int a,int b)
{
    return a > b ? a : b;
}

int smax(int n)
{
    int cmax = 0;
    for(int i = 1;i <= n;i++)
        if(cmax < dp[i]) cmax = dp[i];
    return cmax;
}

int main()
{
    int n,i,j;
    while(scanf("%d",&n) != EOF)
    {
        for(i = 0;i <= n ;i++)  dp[i] = 1;
        for(i = 1;i <= n;i++)    scanf("%lf",&h[i]);
        for(i = 2;i <= n;i++)
            for(j = i - 1;j > 0;j--)
                if(h[i] > h[j] && dp[i] <= dp[j])
                    dp[i] = cmax(dp[i],dp[j] + 1);
        cout << smax(n) <<endl;
    }
    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