HDU 4405:aeroplane Chess probability DP seeking expectation

Source: Internet
Author: User

One person Game Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=4405

Test instructions

There was a man playing flying chess, the rule is: Throw a dice, you can fly from the current point X (x+ points), there are some flight channels on the board, if the point x and Point y there is a flight path, then when you go to the X, you will fly to the point Y, starting at 0, to fly from the beginning to the end of the n need to throw the number of

Exercises

A simple question to ask for, not to expect.

When the point I is the starting point of the flight path, because do not need to throw the dice, you can fly to the end of the flight path, so this time dp[i]=dp[the end of the flight path]

When the point I is not the beginning of the flight path, the dice can fly to i+ points at the time, so at this time DP[I]=∑DP[I+K]*1/6 +1

             

Code

#include <stdio.h>
#include <string.h>
using namespace Std;
const int n=100005;
Double Dp[n];
int q[n];
int main ()
{
int n,m,x,y;
while (~SCANF ("%d%d", &n,&m) && (n| | m))
{
memset (q,0,sizeof (q));
Memset (Dp,0,sizeof (DP));
while (m--)
{
scanf ("%d%d", &x,&y);
Q[x]=y;
}
for (int i=n-1;i>=0;--i)
if (!q[i])
{
for (int j=1;j<=6;++j)
if (i+j<=n) dp[i]+=dp[i+j]/6.0;
dp[i]++;
}
else Dp[i]=dp[q[i]];
printf ("%.4f\n", dp[0]);
}
}

  

HDU 4405:aeroplane Chess probability DP seeking expectation

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.