
Test case : 9
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18
Expected Output: 46652
My code. Pls tell me the error if possible
#include <bits/stdc++.h>
using namespace std;
int dp[10][1025];
int n;
int m=1e9+7;
long long int f(int i, int j, vector &a, vector &b){
if(i==n){
if((1<<n)-1==j) return 1;
return -1;
}
if(dp[i][j]!=-1) return dp[i][j];
long long int ans=INT_MAX;
for(int k=0;k<n;k++){
if((j&(1<<k))==0){
long long int tt=(a[i]+b[k]);
long long int ss=f(i+1,j+(1<<k),a,b);
if(ss<0) continue;
tt=(tt*ss%m)%m;
ans=min(ans,tt);
}
}
return dp[i][j]=ans;}
int main() {
cin>>n;
vector a(n);
vector b(n);
for(auto &c: a) cin>>c;
for(auto &c: b) cin>>c;
memset(dp,-1,sizeof(dp));
cout<<f(0,0,a,b);
}
@cpcs