#include<bits/stdc++.h>#define int long longusingnamespacestd;constintINF=0x3f3f3f3f;constintM=1e9+7;constintmaxn=21;intn;inta[maxn][maxn];intdp[1<<maxn];signedmain(){cin>>n;for(inti=0;i<n;i++){for(intj=0;j<n;j++){cin>>a[i][j];}}dp[0]=1;for(intmask=1;mask<(1<<n);mask++){intnow=__builtin_popcount(mask)-1;for(inti=0;i<n;i++){if((mask&(1<<i)&&a[now][i])){dp[mask]+=dp[mask^(1<<i)];dp[mask]%=M;}}}cout<<dp[(1<<n)-1];}
#include<bits/stdc++.h>#define int long longusingnamespacestd;constintINF=2e18;constintMAXN=1<<22;intn,x;intw[MAXN],dp[MAXN],t[MAXN];signedmain(){cin>>n>>x;for(inti=0;i<n;i++){cin>>w[i];}dp[0]=1;t[0]=0;for(intmask=1;mask<(1<<n);mask++){dp[mask]=INF;t[mask]=INF;for(inti=0;i<n;i++){if(mask&(1<<i)){intS=mask^(1<<i);if(w[i]+t[S]<=x){if(dp[S]<dp[mask]||(dp[S]==dp[mask]&&t[S]+w[i]<t[mask])){t[mask]=t[S]+w[i];dp[mask]=dp[S];}}else{if(dp[S]+1<dp[mask]||(dp[S]+1==dp[mask]&&t[S]+w[i]<t[mask])){t[mask]=w[i];dp[mask]=dp[S]+1;}}}}}cout<<dp[(1<<n)-1]<<"\n";}
#include<bits/stdc++.h>#define int long longusingnamespacestd;intn,v[22][22];strings;intdp[1<<22];intcost(inta,intb,intc){intret=v[a][b]+v[a][c]+v[b][c];returnret;}intsolve(intmask){if(dp[mask]>-1)returndp[mask];if(!mask)return0;intmn=1e9;for(inti=0;i<n;i++){if(!((1<<i)&mask))continue;for(intj=i+1;j<n;j++){if(!((1<<j)&mask))continue;for(intk=j+1;k<n;k++){if(!((1<<k)&mask))continue;mn=min(mn,solve(mask^(1<<i)^(1<<j)^(1<<k))+cost(i,j,k));}}break;}returndp[mask]=mn;}signedmain(){intt;cin>>t;while(t--){cin>>n;for(inti=0;i<n;i++){for(intj=0;j<n;j++){cin>>v[i][j];}}for(inti=0;i<(1<<n);i++){dp[i]=-1;}cout<<solve((1<<n)-1)<<"\n";}}
#include<bits/stdc++.h>#define int long longusingnamespacestd;constintINF=(1LL<<60);intdp[(1<<16)][17],t[17];inticeil(inta,intb){if(b<0)a*=-1,b*=-1;if(a>0)return(a+b-1)/b;elsereturna/b;}signedmain(){ios_base::sync_with_stdio(0);cin.tie(0);intn;cin>>n;for(inti=0;i<n;i++){cin>>t[i];}memset(dp,0x3f,sizeof(dp));dp[0][0]=1;for(intmask=1;mask<(1<<n);mask++){for(inti=0;i<n;i++){if(mask&(1<<i)==0)continue;for(intj=0;j<n;j++){inttime=dp[mask^(1<<i)][j]+abs(j-i);dp[mask][i]=min(dp[mask][i],iceil(time,t[i])*t[i]);}}}intans=INF;for(inti=0;i<n;i++){ans=min(ans,dp[(1<<n)-1][i]);}cout<<ans<<'\n';}