标签:max put oca one algorithm logs pre scanf use
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7579 | Accepted: 4559 |
Description
Input
Output
Sample Input
8 7 2 1 8 4 3 5 6
Sample Output
17
简单dp,设f[i][0]表示选了到i个,用完奇数时间的最大值,f[i][1]表示选到第i个,用完偶数时间的最大值,转移方程显而易见。
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 int n; 9 int a[150005]; 10 int f[2][2]; 11 int main() 12 { 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 15 int now=1; 16 bool hh=0; 17 for(int i=1;i<=n;i++) 18 { 19 hh^=1; 20 f[hh][1]=max(f[hh^1][1],f[hh^1][0]+a[i]); 21 f[hh][0]=max(f[hh^1][1]-a[i],f[hh^1][0]); 22 } 23 cout<<max(f[hh][1],f[hh][2]); 24 //system("pause"); 25 }
标签:max put oca one algorithm logs pre scanf use
原文地址:http://www.cnblogs.com/wls001/p/7112810.html