HDU 4576 Robot (probability DP)

Source: Internet
Author: User

// Hdu robot # include <cstdio> # include <iostream> # include <cmath> # include <cstring> using namespace std; inline void RD (int & ret) {char c; do {c = getchar () ;}while (c <'0' | c> '9'); ret = c-'0 '; while (c = getchar ()> = '0' & c <= '9') ret = ret * 10 + (c-'0 ');} int n, m, l, r, w; double dp [2] [222]; // probability int main () of step I operation at Point j () {while (scanf ("% d", & n, & m, & l, & r )! = EOF) {if (n = 0 & m = 0 & l = 0 & r = 0) break; for (int I = 0; I <n; I ++) dp [0] [I] = 0; dp [0] [0] = 1; int cur = 0; while (m --) {RD (w); for (int j = 0; j <n; ++ j) {// card constant optimization. If it is from 1 to n, it must be changed to I <= n, determine whether I is equal to n dp [1-cur] [j] = dp [cur] [(j + w) % n] * 0.5 + dp [cur] [(j-w + n) % n] * 0.5;} cur = 1-cur;} double ans = 0; for (int I = L-1; I <r; ++ I) {ans + = dp [cur] [I];} printf ("%. 4f \ n ", ans);} return 0 ;} // Hdu robot # include <cstdio> # include <iostream> # include <cmath> # include <cstring> using namespace std; inline void RD (int & ret) {char c; do {c = getchar () ;}while (c <'0' | c> '9'); ret = c-'0 '; while (c = getchar ()> = '0' & c <= '9') ret = ret * 10 + (c-'0 ');} int n, m, l, r, w; double dp [2] [222]; // probability int main () of step I operation at Point j () {while (scanf ("% d", & n, & m, & l, & r )! = EOF) {if (n = 0 & m = 0 & l = 0 & r = 0) break; for (int I = 0; I <n; I ++) dp [0] [I] = 0; dp [0] [0] = 1; int cur = 0; while (m --) {RD (w); for (int j = 0; j <n; ++ j) {// card constant optimization. If it is from 1 to n, it must be changed to I <= n, determine whether I is equal to n dp [1-cur] [j] = dp [cur] [(j + w) % n] * 0.5 + dp [cur] [(j-w + n) % n] * 0.5;} cur = 1-cur;} double ans = 0; for (int I = L-1; I <r; ++ I) {ans + = dp [cur] [I];} printf ("%. 4f \ n ", ans);} return 0 ;}

 

Related Article

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.