BZOJ4197 Sushi Dinner (NOI2015)-pressure dp+ number theory __ Dynamic Programming-State compression DP

Source: Internet
Author: User

Test Address: Sushi Dinner
procedure: The subject needs to use the pressure dp+ number theory.
Considering n n n Small, we find that the problem condition is equivalent to the set of mass factors of the number chosen by two persons. So we let F (i,j,k) F (i, J, K) F (i,j,k) take into account the number of former I I I, where the first person takes the number of the mass factor set for J J J, the second The number of people taken by the mass factor set of K K of the scheme number, the state transfer equation should be well written, see the code, the technique of enumerating subsets can be done O (n3p (n)) O (n 3 p (n)) O (N3^{p (n)}), where P (n) p (n) p (n) is n n The number of the mass within. The answer is ∑j∩k=∅f (n,j,k) ∑j∩k =∅f (N, J, K) \sum_{j\cap k=\varnothing}f (n,j,k).
But when n n is bigger, obviously the above method will time out, how to do it. We found that each number contains at most one >n−−√> n >\sqrt N of the mass factor, which is very good, and we can consider the contribution of this mass factor to the answer when it is a certain number x x x. So we compress the ≤n−−√≤n \le \sqrt N, and then take the number without >n−−√> n >\sqrt N-Mass factor out of the above method, and then the enumeration is larger than the N−−√n

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.