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