Reagrding Base Case

In the code of Tiliing Problem why the base case is 1.
i.e dp[0]=1
void solve()
{
int mod=1e9+7;
int n;
int m;
cin>>n>>m;
int dp[n+1];
dp[0]=1;
for(int i=1;i<=n;i++){
dp[i]=dp[i-1];
if(i>=m)
dp[i]=dp[i]+dp[i-m];
dp[i]=dp[i]%mod;

}
cout<<dp[n]<<'\n';

}
In this code

hello @tichibandhilki

that is done to make implementation easier.

here for i=m , dp[i-m]= dp[0] , so if u put dp[0]=0.
then it will give wrong result.
thats why to make it correct we wrote dp[0]=1.(some says ways of arranging 0 tiles is 1)

if u dont want to write dp[0]=1
then simple handle i==m case seprately .
if(i==m) then dp[i]=2;
if(i<m) then dp[i]=1

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.