Hdu 4336 Card Collector (state probability DP | rejection principle)

Source: Internet
Author: User

Hdu 4336 Card Collector (state probability DP | rejection principle)

For more information, see the kuangbin article.

Kuangbin Link

Let's talk about our understanding and explanation of the kuangbin code and the enumeration of the element of the refresh principle bit. I hope it will be helpful to you.

Status dp ac code: I will not go into details about the state compression idea. I just want to understand it. Here I just want to analyze the state equation.

Due to the large amount of data, some of them are replaced by text, which is conducive to the description.

Dp [I] indicates that the I state reaches the full state (that is, the collection of n full items, hereinafter referred to as the full state) the expected.

X items are collected in the I state, and n-x items are not collected.

Then dp [I] = p * dp [I] + p2 * dp [i2] + 1;

Here we will explain the above variables:

P indicates that if the next time an item is drawn, it is the sum of the probabilities of items that have been collected. Why is this so? Should we know the probability DP basis? State decomposition, the sum of events.

P2 indicates the probability that an item has not been collected. After the item has been added, the state will reach the expectation of full State. Here, an accumulation is missing, and all the items that have not been collected will be accumulated. It is still based on the state decomposition and the sum of events.

If you have any questions, please feel free to comment.

#include
 
  #include
  
   #include
   
    using namespace std;double dp[1 << 22];double p[22];int main(){int n;while (cin >> n){double op = 0;for (int i = 0; i 
    
     = 0; i--){double x = 0, sum = 1;for (int j = 0; j < n;j++)if (i&(1 << j)) x += p[j];else            sum += p[j] * dp[i|(1 << j)];dp[i] = sum / (1 - op - x);}printf("%.5lf\n", dp[0]);}}
    
   
  
 


Application of the anti-DDoS principle: Bit operation Enumeration

Here, you may need Baidu to find out what the review principle is, and then I will explain it clearly, because I do not know how to explain the review principle, here is an article recommended by others. Refresh Principle

Now, you may have understood what the anti-DDoS principle is.

Here, we use n = 3 as an example. The following describes how to compress data by status.

I want to get 111

So 1/p1 (p1 indicates the probability of Event 1) indicates the probability of occurrence of 1, which includes 001,011,111,101

Similarly, 1/p2 includes 010,011,111,110

1/p3: 100,101,111,110

After adding the three, the expected state is 001,010,100,011*2,101*2,110*2,111*3. What we need is the 111 state, so we need to find a way to subtract other

1/(p2 + p1) includes, 011,010,001,111,110,101

1/(p2 + p3) includes 110,100,010,111,101,011

1/(p3 + p1) includes 101,001,100,111,011,110

1/(p1 + p2 + p3) includes 001,010,100,110,011,101,111

Based on the refresh principle, subtract the three above and get: (all negative) 001,010,100,110,011,101

Therefore, add 1/(p1 + p2 + p3) to get the expected 111 status.

1/p corresponds to expectations. I hope you can understand it for a long time. If you have any questions, please contact me. QQ: 417033420

#include
 
  #include
  
   #include
   
    #includeusing namespace std;double p[22];int main(){int n;while (scanf("%d", &n) == 1){for (int i = 0; i
    
     

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.