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 |
还请指教:用DP求解,为何WA?代码如下:#include <iostream> const int maxn=100000; int price[maxn], d[maxn],L,best; int dp(int i) { int &ans=d[i]; if(ans>0) return ans; ans=1; for(int j=i+1; j<L; j++) if(price[j]>price[i]) { if(ans<dp(j)+1) ans=dp(j)+1; } return ans; } int main() { freopen("A.IN","r",stdin); while(scanf("%d", &L)!=EOF) { best=1; for(int i=0; i<L; i++) scanf("%d",&price[i]); memset(d, -1, sizeof(d)); for(int i=0; i<L; i++){ if(best<dp(i)) best=dp(i);} printf("%d\n", best); } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator