[Ybtoj High-efficiency Advanced 1.1] [Recursion] Tiling scheme
topic
Problem-solving ideas
Let f[n] be the number of plans when the length is n
n=1
When n==2
When n>=3
- The last one is placed vertically 2*1, there are f[n-1] kinds of schemes
- The last one is 2*2, there are f[n-2] kinds of schemes
- The last one is to put 2 2*1 horizontally, there are f[n-2] kinds of schemes
Code
#include<iostream>
#include<cstdio>
using namespace std;
struct lzf{
int l,a[120];
}f[300];
int n;
void gj(int x)
{
int t=0;
for (int i=1;i<=f[x-2].l;i++)
{
f[x].a[i]=f[x-2].a[i]*2+t;
t=f[x].a[i]/10;
f[x].a[i]=f[x].a[i]%10;
}
if (t>0)
f[x].l=f[x-2].l+1,f[x].a[f[x].l]=t;
t=0;
f[x].l=max(f[x].l,f[x-1].l);
for (int i=1;i<=f[x].l;i++)
{
f[x].a[i]=f[x].a[i]+t+f[x-1].a[i];
t=f[x].a[i]/10;
f[x].a[i]=f[x].a[i]%10;
}
if (t)
f[x].l++,f[x].a[f[x].l]=t;
}
int main()
{
f[1].l=1;
f[1].a[1]=1;
f[2].l=1;
f[2].a[1]=3;
for (int i=3;i<=250;i++)
gj(i);
while (scanf("%d",&n)>0)
{
for (int i=f[n].l;i>0;i--)
printf("%d",f[n].a[i]);
printf("\n");
}
return 0;
}