HDU 4405 aeroplane chess

Source: Internet
Author: User

Question:

Hzz starts at 0, and then hzz throws the dice. If the dice is I, it goes forward to step I. When the position of hzz is greater than or equal to N, it ends and calculates the expected number of dice.

With M direct points (x, y), you can directly go to Y

Expect to push from the back

When I is not equal to any x

DP [I] = seg (1/6 * DP [I + k]) + 1

Otherwise

DP [I] = DP [y]

 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h>10 using namespace std;11 #define pb push_back12 struct node{13     int x,y;14 }p[1010];15 int cmp(node a,node b){16     return a.x<b.x;17 }18 int main()19 {20     int n,m;21     while(cin>>n>>m,n+m){22         double dp[101010];23         memset(dp,0,sizeof(dp));24         for(int i=0;i<m;i++)25             scanf("%d%d",&p[i].x,&p[i].y);26         sort(p,p+m,cmp);27         int cnt=m-1;28         for(int i=n-1;i>=0;i--){29               dp[i]=1;30               if(cnt>=0&&i==p[cnt].x){31                dp[i]=dp[p[cnt].y];32                cnt--;33                continue;34               }35               for(int j=6;j>=1;j--)36                 dp[i]+=1.0/6*dp[i+j];37         }38         printf("%.4f\n",dp[0]);39     }40 }

 

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.