The topic probably said to eat n food in m, eat each food will get a certain degree of satisfaction, some food if eat after some food will increase satisfaction, ask how to eat the highest satisfaction.
- Dp[s][i] means that the food set that has been eaten is S and is just eating the maximum satisfaction of the first I food
。。 There's nothing to say.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 intval[ -],pairs[ -][ -];6 Long Longd[1<< -][ -];7 8 intGETCNT (ints) {9 intCnt=0;Ten for(intI=0; i< -; ++i) { One if(s>>i&1) ++CNT; A } - returnCNT; - } the - intMain () { - intn,m,k; -scanf"%d%d%d",&n,&m,&k); + for(intI=0; i<n; ++i) { -scanf"%d", val+i); + } A inta,b,c; at while(k--){ -scanf"%d%d%d",&a,&b,&c); ---a; --b; -pairs[a][b]=C; - } - for(intI=0; i<n; ++i) { ind[1<<i][i]=Val[i]; - } to for(ints=0; s< (1<<N); ++s) { + for(intI=0; i<n; ++i) { - if((s>>i&1)==0)Continue; the for(intj=0; j<n; ++j) { * if(I==j | | (s>>j&1)==0)Continue; $D[s][i]=max (d[s][i],d[s^ (1<<i)][j]+val[i]+pairs[i][j]);Panax Notoginseng } - } the } + Long Longres=0; A for(ints=0; s< (1<<N); ++R) { the if(getcnt (s)!=m)Continue; + for(intI=0; i<n; ++i) { -res=Max (res,d[s][i]); $ } $ } -printf"%lld", res); - return 0; the}
Codeforces 580D Kefa and dishes (pressure DP)