I\'m trying to solve a slightly modified version of the Hamiltonian Path problem. It is modified in that the start and end points are given to us and instead of determining
It can be solved using DP with bitmasking for values of n upto 20 or a few more i guess. Create a 2d dp table. dp[i][j] represents the answer of case that you are on ith vertex and j stores the information about visited vertices.Here's a C++ code.
Macros used:
#define oncnt __builtin_popcount
typedef vector vi;
Outside Main:
vi ad[21];
int n,m;
int dp[20][(1<<19)+1];
int sol(int i,int mask)
{
//cout<
Inside Main:
cin>>n>>m;
for(int i=0;i<=n-1;i++)
{
for(int j=0;j<=(1<<(n-1));j++)
dp[i][j]=-1;
}
int a,b;
for(int i=1;i<=m;i++)
{
cin>>a>>b;
a--;
b--;
ad[a].pb(b);
}
cout<