Jump to content
Fórum Script Brasil
  • 0

AJUDA para entendimento de algoritmo


ahhsxxx

Question

Dont get rooked

#include <iostream>

#include<string.h>

#include <stdio.h>

#include <cmath>

using namespace std;

int n ;

int tab[4][4];

void cancelar(int r,int c ,int estado)

{

int i;

for(i=c;i<n && tab[r] != -1;i++)

tab[r] +=estado;

for(i=r;i<n && tab[c] != -1;i++)

tab[c] +=estado;

}

int resolver(int pos,int torres)

{

int mx = torres;

int i;

for(i=pos;i<16;i++)

if(tab[i/4][i%4]==0)

{

cancelar(i/4,i%4 ,1);

//retorna o maior

mx = max(resolver(i+1 , torres+1) , mx);

cancelar(i/4,i%4,-1);

}

return mx;

}

int main()

{

cin >> n;

while(n)

{

int i,j;

char c;

memset(tab , -1,sizeof(int)*16);

for(i=0;i<n;i++) {

for(j=0;j<n;j++)

{

cin >> c;

if(c == '.')

tab[j] = 0;

}

}

int resolucao = resolver(0,0);

cout << resolucao << endl;

cin >> n;

}

return 0;

}

tenho que apresentar esse algoritmo do uva em sala de aula e n sou muito bom com lógica de programação... o algoritmo consiste num tabuleiro onde são colocados o máximo de torres possiveis sem q elas se encontrem ou se matem! té +

Edited by ahhsxxx
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...