DP + state compression-codeforces 580D Kefa and dishes

Source: Internet
Author: User

Kefa and Dishes
problem ' s Link

 

Mean:

There are N-course dishes on the menu, which requires a little M-channel. The delicious value of each dish is AI.

There are k rules, each rule: after eating the first XI course after eating Yi can get more delicious value of VI.

Q: How many delicious values can I get?

(1≤m≤n≤18,0≤k≤n∗ (n−1))

Analyse:

Classic pressure DP.

Due to a maximum of 18 courses, a number of S (s<=2^18) can be used to uniquely identify a state.

For a state s, enumerate two positions I and j:i selected from the selected Dish, J is selected from the dish that has never been selected.

The next state SS is the maximum value of all states after eating I and then eating J.

Transfer process:ss=s| ( 1<<J)

State transition equation:dp[ss][j]=max (Dp[ss][j],dp[s][i]+sa[j]+ad[i][j])

The answer is the maximum value of all the selected quantities up to M.

Time complexity:o ((2^N) * ( n^2))

 

View Code

DP + state compression-codeforces 580D Kefa and dishes

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.