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