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: 参考了别人的,加了一些注释的版本,希望有助理解。// 2533. 最长递增子序列 /* // 误以为是dp[i-1]+1 dp[i] = max(dp[j]+1, dp[i]) dp 初始化为1! */ #include<iostream> using namespace std; #define MAXN 1002 int main(){ int N,nbr; int n[MAXN],dp[MAXN]; char ch; cin>>N; for(int i=0; i<=N; i++) dp[i] = 1; int m = 1;// 最大值 for(int i=1; i<=N; i++){// i: 前i个的最长长度 cin>>n[i]; for (int j = 1; j<=i; j++){// j: 当前最大数的位置 if (n[j] < n[i]){ dp[i] = max(dp[j] + 1, dp[i]); if(dp[i] > m){ m = dp[i]; } } } } cout<<m<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator