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

why tle??

Posted by BJ051155 at 2007-09-17 13:41:05 on Problem 3378
#include <stdio.h>
#include <iostream>
using namespace std;
int n;
#define MAX 1000000001
__int64 num[50001];
unsigned __int64 res[50001][6];
unsigned __int64 total;

unsigned __int64 dp(int id,int cou)
{
	if(res[id][cou]!=-1)
		return res[id][cou];
	if(cou==1)
	{
		res[id][cou]=1;
		return 1;
	}
	res[id][cou]=0;
	for(int i=1;i<id;i++)
		if(num[i]<num[id])
			res[id][cou]+=dp(i,cou-1);
	return res[id][cou];
}

void work()
{	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=5;j++)
			res[i][j]=-1;
	total=0;
	for(i=n;i>=5;i--)
		total+=dp(i,5);

}

int main(int argc, char* argv[])
{
	while(scanf("%d",&n)==1)
	{
		for(int i=1;i<=n;i++)
			scanf("%I64d",num+i);
		work();
		printf("%u\n",total);
	}
	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