# 【EOJ 3297. 铺瓷砖】（dfs，记忆化）

Time limit per test: 2.0 seconds

Memory limit: 256 megabytes

例如，长度为4的地面一共有如下3种铺法，并且，一共用了长度为1的瓷砖4块：
4=1+2+1
4=1+3
4=3+1

Input

Output

Examples
input
1
4
output
3
4

n过大时，记忆化防T

#include <bits/stdc++.h>
using namespace std;

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define dec(i,n,a) for(int i=n;i>=a;i--)///[n,a]
#define pb push_back
#define fi first
#define se second
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MOD=258280327;
const int N=30+5;
const ll maxn=1e6+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
int f[N][2],cnt,ans;
void dfs(int sum,int pre,int num)
{
if(sum<0) return ;
if(!sum)
{
ans++;
cnt+=num;
return;
}
rep(i,1,4)
{
if(i!=pre)
{
if(i==1) dfs(sum-i,i,num+1);
else dfs(sum-i,i,num);
}
}
}
int main()
{
int T,n;
scanf("%d",&T);
mem(f,-1);
while(T--)
{
scanf("%d",&n);
if(f[n][0]!=-1&&f[n][1]!=-1)
{
printf("%d\n%d\n",f[n][0],f[n][1]);
continue;
}
ans=cnt=0;
dfs(n,0,0);
f[n][0]=ans,f[n][1]=cnt;
printf("%d\n%d\n",ans,cnt);
}
return 0;
}