solution of DP with bitmasks...

```
#include<bits/stdc++.h>
using namespace std;
int soln(int i,int mask,int n,vector<vector<int>> cost,vector<vector<int>> &dp)
{
if(i==n)
return 0;
if(dp[i][mask]!=-1)
return dp[i][mask];
int ans=0;
for(int j=0;j<n;j++)
{
//check if item is already taken from another shop...
if(mask & (1<<j))
continue;
//if not taken take that item and set its mask...
ans=max(ans , cost[i][j]+soln(i+1,mask|(1<<j),n,cost,dp));
}
return dp[i][mask]=ans;
}
int main()
{
int n;
cin>>n;
vector<vector<int>> cost(n,vector<int>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>cost[i][j];
}
}
vector<vector<int>> dp(n+10,vector<int>(n+10,-1));
cout<<soln(0,0,n,cost,dp);
}
```