?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
192701811 |
Practice: hydra_cody |
580D - 11 | C++17 (GCC 7-32) | Accepted | 779 ms | 36948 KB | 2023-02-08 10:39:38 | 2023-02-08 10:39:38 |
//Kefa and Dishes # include <bits/stdc++.h> using namespace std; # define mod 1000000007 # define ll long long # define INF 1e18 # define mp make_pair # define pb push_back # define fill(a,v) memset(a, v, sizeof a) ll N,M,K; ll arr[18]; ll dp[18][1<<18]; ll follow[18][18]; ll fun(ll idx,ll vis) { // ll count1s=0; ll i,j; // for(i=0;i<N;i++) // { // if((vis&(1<<i))>0) // count1s++; // } //cout<<count1s<<"<--count1s for this"<<endl; if(__builtin_popcountll(vis)==M) return arr[idx]; if(dp[idx][vis]!=-1) return dp[idx][vis]; ll temp=arr[idx]; for(i=0;i<N;i++) { if((vis&(1<<i))==0) temp=max(temp,arr[idx]+follow[idx][i]+fun(i,(vis|(1<<i)))); } //cout<<temp<<"<--dp val for "<<idx<<"<--idx "<<vis<<"<--vis "<<endl; return dp[idx][vis]=temp; } int main() { ll i,j; fill(dp,-1); fill(follow,0); scanf("%lld%lld%lld",&N,&M,&K); for(i=0;i<N;i++) scanf("%lld",&arr[i]); while(K--) { ll X,Y,C; scanf("%lld%lld%lld",&X,&Y,&C); follow[X-1][Y-1]=C; } ll ans=0; for(i=0;i<N;i++) ans=max(ans,fun(i,(1<<i))); printf("%lld\n",ans); return 0; }
?
?
?
?