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

动态规划第一题 值得纪念!~

Posted by abilitytao at 2008-09-25 00:50:48 on Problem 1887
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;


int num[10000];
int dp[10000];

int main()
{
	int n;
	int i,j;
	int len;
	int max;
	int finalmax;
	int flag=1;
	while(scanf("%d",&n))
	{
		if(n==-1)
			break;
		num[0]=n;
		for(i=1;;i++)
		{
			scanf("%d",&n);
			if(n==-1)
				break;
			else
				num[i]=n;
		}
		len=i-1;

		dp[len]=1;

		for(i=len-1;i>=0;i--)
		{
			max=0;
			for(j=i+1;j<=len;j++)
			{
				if(dp[j]>max&&num[j]<num[i])
					max=dp[j];
			}
			dp[i]=max+1;
		}
		finalmax=0;
		for(i=0;i<=len;i++)
		{
			if(dp[i]>finalmax)
				finalmax=dp[i];
		}
		printf("Test #%d:\n  maximum possible interceptions: %d\n\n",flag,finalmax);
		flag++;
	}
	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