![]() | ![]() | Problem Statement | ![]() |
![]()
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
-------------------------------------------------------------code--------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli dp[6][6][100];
lli solve(int i,int j,int n,int arr[6][5],int N )
{
if(arr[i][j]==-1) return 0;
else if(n==N)
return 1;
if(dp[i][j][n]!=-1) return dp[i][j][n];
else
{
lli ret=0;
ret+= solve(i+1,j,n+1,arr,N);
ret+= solve(i-1,j,n+1,arr,N);
ret+= solve(i,j+1,n+1,arr,N);
ret+= solve(i,j-1,n+1,arr,N);
dp[i][j][n]=ret;
return ret;
}
}
long long countPasswords(int N)
{
int arr[6][5] =
{
{-1,-1,-1,-1,-1},
{-1,1,2,3,-1},
{-1,4,5,6,-1},
{-1,7,8,9,-1},
{-1,0,-1,-1,-1},
{-1,-1,-1,-1,-1}
};
memset(dp,-1,sizeof dp);
long long ans=0;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=3;j++)
{
if(arr[i][j]!=-1)
{
ans+=solve(i,j,1,arr,N);
}
}
}
return ans;
}
int main()
{
int n;
cin>>n;
cout<< countPasswords(n)<<endl;
}
No comments:
Post a Comment