标签:fine algorithm 最大值 iss double text long 需要 inpu
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38985 Accepted Submission(s): 15293
1 #include "cstdio" 2 #include "algorithm" 3 #include "cstring" 4 #include "queue" 5 #include "cmath" 6 #include "vector" 7 #include "map" 8 #include "stdlib.h" 9 #include "set" 10 typedef long long ll; 11 using namespace std; 12 const int N=1e6+5; 13 const int mod=1e9+7; 14 #define db double 15 //int a[N]; 16 //set<int> q; 17 //map<int ,int > u; 18 //ll dp[N]; 19 int a[N]; 20 int dp[N]; 21 int main() 22 { 23 int n; 24 while (scanf("%d",&n)==1){ 25 for(int i=0;i<n;i++){ 26 scanf("%d",&a[i]); 27 } 28 for(int i=0;i<n;i++){ 29 dp[i]=1; 30 } 31 int ans=-1; 32 for(int i=0;i<n;i++){ 33 for(int j=0;j<i;j++){ 34 if(a[i]>a[j]){ 35 dp[i]=max(dp[i],dp[j]+1); 36 ans=max(dp[i],ans); 37 } 38 39 } 40 } 41 printf("%d\n",ans); 42 } 43 return 0; 44 }
贪心代码:
1 #include "cstdio" 2 #include "algorithm" 3 #include "cstring" 4 #include "queue" 5 #include "cmath" 6 #include "vector" 7 #include "map" 8 #include "stdlib.h" 9 #include "set" 10 typedef long long ll; 11 using namespace std; 12 const int N=1e6+5; 13 const int mod=1e9+7; 14 #define db double 15 //int a[N]; 16 //set<int> q; 17 //map<int ,int > u; 18 //ll dp[N]; 19 int a[N]; 20 int h[N]; 21 int main() 22 { 23 int n; 24 while (scanf("%d",&n)==1){ 25 memset(h,0, sizeof(h)); 26 int v=1; 27 for(int i=0;i<n;i++) 28 scanf("%d",&a[i]); 29 h[1]=a[0]; 30 for(int i=0;i<n;i++){ 31 if(a[i]<=h[v]){ 32 for(int j=1;j<=v;j++){ 33 if(a[i]<=h[j]) {h[j]=a[i];break;} 34 } 35 } 36 else h[++v]=a[i]; 37 } 38 printf("%d\n",v); 39 } 40 return 0; 41 }
标签:fine algorithm 最大值 iss double text long 需要 inpu
原文地址:http://www.cnblogs.com/mj-liylho/p/6527368.html