标签:des style class blog code java
2 0 8 3 2 4 4 5 7 8 0 0
1.1667 2.3441
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 100000+10;
double dp[maxn];
map<int,int> t;
map<int,int> flight;
int n,m;
void dfs(int sta,int x){
if(t[x]==0){
flight[sta] = x;
}else{
dfs(sta,t[x]);
}
}
void init(){
for(map<int,int>::iterator it = t.begin(); it != t.end(); it++){
dfs(it->first,it->second);
}
}
int main(){
while(cin >> n >> m && n+m){
t.clear();
flight.clear();
while(m--){
int a,b;
scanf("%d%d",&a,&b);
t[a] = b;
}
init();
dp[n] = 0;
for(int i = n-1; i >= 0; i--){
dp[i] = 1;
for(int k = 1; k <= 6; k++){
if(i+k <= n){
if(flight[i+k]==0){
dp[i] += dp[i+k]/6;
}else{
dp[i] += dp[flight[i+k]]/6;
}
}
}
}
printf("%.4lf\n",dp[0]);
}
return 0;
}
HDU4405-Aeroplane chess(概率DP求期望),布布扣,bubuko.com
HDU4405-Aeroplane chess(概率DP求期望)
标签:des style class blog code java
原文地址:http://blog.csdn.net/mowayao/article/details/34120121