标签:ges sep include long style first red fine names
7 1 7 3 5 9 4 8Sample Output
4
动态规划
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <map> #define Max 1001 using namespace std; int s[1000]; int dp[1001]; int main() { int n,d = 0; while(cin>>n){ d = 1; for(int i = 1;i <= n;i ++) { dp[i] = 1; cin>>s[i]; } for(int i = 2;i <= n;i ++) { for(int j = 1;j < i;j ++) if(s[i] > s[j])dp[i] = max(dp[i],dp[j] + 1); d = max(d,dp[i]); } cout<<d<<endl;} }
二分加数组
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <map> #define Max 1001 using namespace std; int main() { int n,d,no; int s[100000]; while(cin>>n) { no = 0; while(n --) { cin>>d; if(!no || s[no - 1] < d)s[no ++] = d; else { int *p = upper_bound(s,s + no,d); *p = d; } } cout<<no<<endl; } }
标签:ges sep include long style first red fine names
原文地址:http://www.cnblogs.com/8023spz/p/7966968.html