Note that there are some explanatory texts on larger screens.

plurals
  1. PONumber of combinations with LEGO plastic bricks C++
    primarykey
    data
    text
    <p>You have some LEGO plastic bricks, all bricks are 1x1x1. Also you have one tile, 1xN (N &lt;= 80), on which you should place the LEGO bricks. You can order them in sequences (one sequence is correct if it has 3 or more consecutive bricks), also you must have at least 1 empty space between 2 sequences. You should calculate the number of different combination you can place the bricks on the tiles.</p> <p>Here's an example:</p> <p>If the tile is 1x7, there are 17 different combinations.</p> <p>input : 7 output : 17</p> <p><a href="http://mendo.mk/task_files/kocki.gif" rel="nofollow noreferrer">pic of the example http://mendo.mk/task_files/kocki.gif</a></p> <p>Also if you have no bricks it's counted as 1 combination.</p> <p>I have worked on this problem and i found the way to calculate possible combinations of if the max length of the tile is 14 (3 sequences). I found it using for loops.</p> <p>My biggest problem is the huge number of for loops that i need to run. For example, for 1 sequence i use 1 for loops, for 2 sequences 2 loops + 1 for 1 sequnce...so if i use all 80 bricks, i can create 20 sequence and i will have to use over 210 for loops which is huge number. So it'll be good if i can nest them in one. I tried it and it get messy and it doesn't give correct answers.</p> <p>New code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { long long int places, combinations = 1; cin &gt;&gt; places; long long int f[80], g[80]; f[0] = 0; f[1] = 0; f[2] = 0; g[0] = 1; g[1] = 1; g[2] = 1; for(int i = 3; i&lt;=places; i++) { f[i] = f[i-1] + g[i-3]; g[i] = f[i-1] + g[i-1]; } combinations = f[places] + g[places]; cout &lt;&lt; combinations; return 0; } </code></pre>
    singulars
    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.
 

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