HDU 4405 aeroplane Chess probability DP

Source: Internet
Author: User

Transmission Door

To 0-n so many lattice, initial in 0, and then throw the dice, throw to a few steps, some of which are connected, such as 2,5 connected, then to 2 can fly directly to 5. Ask for the desired number of steps at N.

The first must be backwards, dp[n] = 0. Then if x, Y (x<y) is connected, then dp[x] = Dp[y]. The transfer equation is very well written. See Code for details

1#include <bits/stdc++.h>2 using namespacestd;3 #defineMem (a) memset (a, 0, sizeof (a))4 Doubledp[100005];5 intNum, f[100005], vis[100005];6 intMain ()7 {8     intN, m, x, y;9      while(cin>>n>>m) {Ten         if(n+m==0) One              Break; A mem1 (f); -          while(m--) { -scanf"%d%d", &x, &y); theF[X] =y; -         } - Mem (DP); - mem (VIS); +Dp[n] =0; -          for(inti = n1; i>=0; i--) { +             if(~F[i]) { ADp[i] =Dp[f[i]]; at}Else { -                  for(intj =1; j<=6; J + +) { -Dp[i] + = (1+DP[I+J])/6.0; -                 } -             } -         } inprintf"%.4f\n", dp[0]); -     } to}
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMem (a) memset (a, 0, sizeof (a))4 Doubledp[100005];5 intNum, f[100005], vis[100005];6 intMain ()7 {8     intN, m, x, y;9      while(cin>>n>>m) {Ten         if(n+m==0) One              Break; A mem1 (f); -          while(m--) { -scanf"%d%d", &x, &y); theF[X] =y; -         } - Mem (DP); - mem (VIS); +Dp[n] =0; -          for(inti = n1; i>=0; i--) { +             if(~F[i]) { ADp[i] =Dp[f[i]]; at}Else { -                  for(intj =1; j<=6; J + +) { -Dp[i] + = (1+DP[I+J])/6.0; -                 } -             } -         } inprintf"%.4f\n", dp[0]); -     } to}

HDU 4405 aeroplane Chess 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.