标签:min proc start eve nal called cannot memory content
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36986 Accepted Submission(s):
16885
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 6 int n; 7 long long a[1010],dp[1010]; // dp[i] 储存从0到i的最大上升子序列的和 8 long long LIS() // 最大上升子序列和 9 { 10 int i,j; 11 long long sum = 0, maxx; 12 for (i = 0; i < n; i ++) 13 { 14 dp[i] = a[i]; // dp[i]的初值为a[i] 15 maxx = 0; 16 for (j = 0; j < i; j ++) // 找出i之前的最大dp[i](并保证a[j] < a[i]) 17 { 18 if (a[j] < a[i]) 19 maxx = max(dp[j],maxx); 20 } 21 dp[i] += maxx; 22 sum = max(sum,dp[i]); // sum为最大上升子序列的和 23 } 24 return sum; 25 } 26 int main () 27 { 28 while (scanf("%d",&n),n) 29 { 30 for (int i = 0; i < n; i ++) 31 scanf("%lld",&a[i]); 32 printf("%lld\n",LIS()); 33 } 34 return 0; 35 }
hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)
标签:min proc start eve nal called cannot memory content
原文地址:http://www.cnblogs.com/yoke/p/6691279.html