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 |
why tle??#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator