Expectation for calculation of the probability DP of the WordPress 10529 dumb bones

Source: Internet
Author: User

Question link: Click the open link

Question:

Dominoes should be placed on a straight line.

Input n, l, R

To place n rows, the probability of moving down to the left is l, and the probability of moving to the right is R.

You can adopt the optimal strategy, that is, you can place a segment in the middle, and then place a segment on both sides of the left and right. The placement order is arbitrary.

Q: The expected number of times to place n cards under the best strategy.


Ideas:

Click Open Link

#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <map>#include <cmath>template <class T>inline bool rd(T &ret) {    char c; int sgn;    if(c=getchar(),c==EOF) return 0;    while(c!='-'&&(c<'0'||c>'9')) c=getchar();    sgn=(c=='-')?-1:1;    ret=(c=='-')?0:(c-'0');    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');    ret*=sgn;    return 1;}template <class T>inline void pt(T x) {    if (x <0) {        putchar('-');        x = -x;    }    if(x>9) pt(x/10);    putchar(x%10+'0');}using namespace std;typedef long long ll;#define N 2002const ll mod = 1e9+7;int n;double l, r;double dp[N];double solve(){dp[0] = 0;dp[1] = 1.0/(1.0-l-r);for(int i = 2; i <= n; i++){dp[i] = 1e18;for(int j = 0; j < i; j++){int L = j, R = i-j-1;double x = (1+ dp[L] + dp[R] -dp[L]*r -dp[R]*l) / (1-l-r);dp[i] = min(dp[i], x);}}return dp[n];}int main() {    while(cin>>n>>l>>r, n){        printf("%.2f\n", solve());    }    return 0;}


Expectation for calculation of the probability DP of the WordPress 10529 dumb bones

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.