-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarida_probelm.cpp
More file actions
51 lines (41 loc) · 1002 Bytes
/
Copy pathfarida_probelm.cpp
File metadata and controls
51 lines (41 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long farida(vector<long long> &dp,const vector<long long> &arr,int i,int n){
if( i >= n ){
return 0;
}
if( dp[i] != -1 ){
return dp[i];
}
dp[i] = max(farida(dp,arr,i+1,n) , farida(dp,arr,i+2,n)+arr[i] );
return dp[i];
}
int main()
{
int x;
cin>>x;
for (size_t i = 0; i < x; i++)
{
int n;
cin>>n;
if( n == 0){
cout << "Case " << i + 1 << ": 0" << endl;
continue;
}
vector<long long> arr(n);
for (size_t j = 0; j < n; j++)
{
cin>>arr[j];
}
vector<long long> dp(n,-1);
//cout<<"Case "<<i+1<<":"<<farida(dp,arr,0,n)<<endl;
dp.push_back(0);
for (int p = n-1 ; p >= 0; p--)
{
dp[p] = max(dp[min(p+1,n)],dp[min(p+2,n)]+arr[p]);
}
cout<<"Case "<<i+1<<":"<<dp[0]<<endl;
}
return 0;
}