Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int a[15], n;
- vector<int>seen;
- int sum(int ind){
- int store = 1;
- bool f=false;
- for(int i = ind+1; i<n; i++){
- if(seen[i] == 0){
- store = store*a[i];
- f=true;
- break;
- }
- }
- for(int i=ind-1; i>=0; i--){
- if(seen[i]==0){
- store = store * a[i];
- f=true;
- break;
- }
- }
- if(f==true){
- return store;
- }
- else{
- return a[ind];
- }
- }
- int Brust(int ind){
- if(ind==n){
- return 0;
- }
- int ans = INT_MIN;
- for(int i = 0; i < n; i++){
- if(seen[i]==0){
- seen[i]=1;
- ans = max(ans, Brust(ind+1)+sum(i));
- seen[i]=0;
- }
- }
- return ans;
- }
- int main(){
- cin >> n;
- for( int i = 0; i < n; i++){
- cin >> a[i];
- }
- seen.assign(n, 0);
- cout << Brust(0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement