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 |
经典动态规划题,好!由此题虽然知道用动态规划但有时找状态方程没有那么容易,这也是动态规划中的难点。 今天做了三道经典的动态规划,感觉对动态规划有了更深的理解,但对状态转化方程还、 不太熟,还要努力!! #include"iostream" using namespace std; int num[1001]; int f[1001]; int longest=1; int main() { int n; int max; int i,j,k; cin>>n; for(i=0;i<n;i++) cin>>num[i]; for(j=1;j<n;j++) { max=1; f[0]=1; for(k=0;k<j;k++) { if(num[k]<num[j]) if(f[k]+1>max) max=f[k]+1; } f[j]=max; if(max>longest) longest=max; } cout<<longest<<endl; return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator