You have some LEGO plastic bricks, all bricks are 1x1x1. Also you have one tile, 1xN (N <= 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.
Here's an example:
If the tile is 1x7, there are 17 different combinations.
input : 7 output : 17
(source: mendo.mk)
Also if you have no bricks it's counted as 1 combination.
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.
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.
New code:
#include <iostream>
using namespace std;
int main()
{
long long int places, combinations = 1;
cin >> 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<=places; i++)
{
f[i] = f[i-1] + g[i-3];
g[i] = f[i-1] + g[i-1];
}
combinations = f[places] + g[places];
cout << combinations;
return 0;
}
also you must have at least 1 empty space between 2 sequences
. Your example is not in coherence with this statement – Multiversitybit
of abinary
state, and you basicallyshift
patterns along... :-) – Driving