Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmask functions
    primarykey
    data
    text
    <p>I'm writing a program to find if I can make a square with N sticks of N length. Ive used Bitmask cause its easier for the big input I'm gonna put in there. For some reason, my backtracking code its not returning anything, in this line "bitmask &amp; (1 &lt;&lt; vec[i])" it never goes in. Can someone help me if im using the wrong functions? I've recently learned this, but I cant find info. </p> <p>PD:im not an english speaker, sorry for my grammar and syntax problems.</p> <p>Thanks</p> <pre><code>// 10364 - Square.cpp: archivo de proyecto principal. #include "stdafx.h" #include &lt;stdio.h&gt; #include &lt;vector&gt; using namespace std; vector&lt;int&gt; vec; int bitmask,casos,palitos,suma,maximo; bool analiza(int analizado,int lados)// lados =cantidad lados analizados, contador { if (analizado==maximo) { analizado=0; lados++; } if(lados==4) { printf("yes\n"); return true; } for (int i=0;i&lt;palitos;i++) { if (!(bitmask &amp; (1 &lt;&lt; i))) { if (analizado+vec[i]&lt;=maximo) { bitmask | (1 &lt;&lt; i); if(analiza(analizado+1,lados)) return true; bitmask &amp; ~(1 &lt;&lt; i); } } } return false; //prender: bitmask | (1 &lt;&lt; indice) //apagar: bitmask &amp; ~(1 &lt;&lt; indice) /*comparar: bitmask &amp; (1 &lt;&lt; indice)*/ } int main() { freopen("in.txt","rt",stdin); freopen("out.txt","wt",stdout); scanf("%d\n",&amp;casos); for(int i=0;i&lt;casos;i++) { scanf("%d",&amp;palitos); vec.clear(); vec.resize(palitos); suma=0; for(int j=0;j&lt;palitos;j++) { scanf("%d",&amp;vec[j]); suma+=vec[j]; } if(suma%4!=0) printf("no\n"); else{ bitmask=0; maximo=suma/4; analiza(0,0); } } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload