Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cstring>
- #include <cmath>
- #include <set>
- #include <vector>
- using namespace std;
- vector<int>v;
- vector<int>pot;
- int ncorn;
- int adyacentes(int a,int b){
- if (a==b)
- return 0;
- //En a está el min
- for (int k=1;k<ncorn;k=k*2){
- if ((a^k)==b){
- //cout<<a<<" y "<<b<<" son adyacentes"<<endl;
- //cout<<a<<" xor: "<<k<<"= "<<b<<endl;
- return 1;}
- }
- return 0;
- }
- int potencial(int ind){
- int suma=0;
- for (int i=0;i<ncorn;i++){
- if(adyacentes(ind,i))
- suma=suma+v[i];
- }
- return suma;
- }
- int main() {
- int ndim;
- while(cin>>ndim){
- //cout<<"ndim: "<<ndim<<endl;
- int aux;
- ncorn=pow(2,ndim);
- //cout<<"ncorn: "<<ncorn<<endl;
- for (int i=0;i<ncorn;i++){
- cin>>aux;
- v.push_back(aux);
- }
- //Calcular potenciales
- for (int i=0;i<ncorn;i++){
- pot.push_back(potencial(i));
- //cout<<"potencial de "<<i<<": "<<pot[i]<<endl;
- }
- int suma,max=0;
- for (int i=0;i<ncorn;i++){
- for (int j=0;j<ncorn;j++){
- if (adyacentes(i,j)){
- suma=pot[i]+pot[j];
- if (suma>max)
- max=suma;
- }
- }
- }
- cout<<max<<endl;
- v.clear();
- pot.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement