Codeforces 580D Kefa and dishes (pressure DP)

Source: Internet
Author: User

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&LT;&LT;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&LT;&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.