HDU4576 probability DP

Source: Internet
Author: User

The consciousness of this problem is to give you a ring lattice, from 1-n clockwise, just start the robot in 1, then the robot will walk m times, each walk a quota of the deployment, and then ask you the last robot fell in the range of L-r, the time card is tight, pay attention to the way of writing procedures, using brush table method can be, code as follows

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Doubledp[2][205];intN, M, L, R;intMain () { while(SCANF ("%d%d%d%d", &n, &m, &l, &r) = =4){        if(N+m+l+r = =0) Break; Memset (DP,0,sizeof(DP)); dp[0][0] =1;  for(intI=0; i<m; i++) {memset (dp[(i+1) &1],0,sizeof(dp[0])); intsteps; scanf ("%d", &steps);  for(intj=0; j<n; J + +){                if(dp[i&1][J] = =0.0)Continue; dp[(i+1) &1[(J+steps)%n] + =0.5*dp[i&1][j]; dp[(i+1) &1[((J-steps)%n+n)%n] + =0.5*dp[i&1][j]; }        }        Doubleres =0;  for(intj=l-1; j<=r-1; J + +) Res+ = dp[m&1][j]; printf ("%.4f\n", RES); }    return 0;}

HDU4576 probability DP

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.