hdu4405 概率dp

Problem Description
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz is at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.

There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.

Please help Hzz calculate the expected dice throwing times to finish the game.


Input
There are multiple test cases.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).  
The input end with N=0, M=0.



Output
For each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.


测试案例:

input:

2 0
8 3
2 4
4 5
7 8
0 0


output:

1.1667
2.3441


大致题意:现在有个飞行棋,棋盘从0-n共n个格子,你现在从0开始走,最后要走到大于等于n的位置才能结束,棋盘上有些飞行通道,比如到达2能直接飞到5,然后继续飞到7这种,但是一个格子不会有从他出发的多个飞行通道,你有一个骰子,每次可以投1-6,问从0结束游戏的投色子次数期望是多少




解题思路:设dp[i]表示i到n的期望,那么可以得到dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6+1,另外注意飞行航道和处理离终点6以内的特殊点。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn=100010;
const double t=(double)1/(double)6;

int g[maxn],n,m;
double dp[maxn];

double go(int i,int d)
{

    if (i+d>=n)
        return t;
    int pos=g[i+d];
    while (pos!=-1)
    {
        if (g[pos]==-1)
            break;
        else
        {
            pos=g[pos];
        }
    }
    if (pos==-1)
        pos=i+d;
    return t*(dp[pos]+1);
}

int main()
{
    int i,j,x,y;

    while (scanf("%d%d",&n,&m)==2)
    {
        if (n==0&&m==0)
            break;
        for (i=0;i<=n;i++)
        {
            g[i]=-1;
            dp[i]=0;
        }
        for (i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            g[x]=y;
        }
        for (i=n-1;i>=0;i--)
        {
            for (j=1;j<=6;j++)
            {
                dp[i]+=go(i,j);
            }
        }

        printf("%.4lf\n",dp[0]);
    }
}


内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确点对点运动控制;② 对比分析同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值