标签:other sea memory logs most blog 0ms hal mem
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10369 | Accepted: 3611 |
Description
"Buy low; buy lower"
Day 1 2 3 4 5 6 7 8 9 10 11 12
Price 68 69 54 64 68 64 70 67 78 62 98 87
Day 2 5 6 10
Price 69 68 64 62
Input
Output
Sample Input
12 68 69 54 64 68 64 70 67 78 62 98 87
Sample Output
4 2
Source
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 7 using namespace std; 8 9 int n,mxl,ans,a[6000],f[6000],g[6000]; //f[i]储存以 i为结尾的最长不下降子序列;g[i]储存以 i为结尾的最长不下降子序列的个数 10 11 int main() 12 { 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) 15 scanf("%d",&a[i]); 16 for(int i=1;i<=n;i++) 17 { 18 bool flg=false; 19 for(int j=i-1;j>=1;j--) 20 { 21 if(a[j]==a[i]){flg=true;break;} //防止重复 (样例中情况 ) 22 if(a[j]>a[i]) 23 { 24 if(f[j]+1>f[i]) 25 { 26 f[i]=f[j]+1; 27 g[i]=g[j]; 28 } 29 else if(f[j]+1==f[i]) 30 g[i]+=g[j]; 31 } 32 } 33 if(!flg)f[i]=max(f[i],1),g[i]=max(g[i],1); 34 mxl=max(mxl,f[i]); 35 } 36 for(int i=1;i<=n;i++) 37 { 38 if(f[i]==mxl)ans+=g[i]; 39 } 40 printf("%d %d",mxl,ans); 41 //system("pause"); 42 return 0; 43 }
POJ 1952 -- BUY LOW, BUY LOWER
标签:other sea memory logs most blog 0ms hal mem
原文地址:http://www.cnblogs.com/YXY-1211/p/7137859.html