HDU 4405 Aeroplane chess(概率DP入门)
2015-07-10 08:58
471 查看
开始把dp[i] 设成了 从0到>=i的期望值。。。。然后差点跪了。。。确实是个水题。。不过头脑灵活一下。
思路:设dp[i] 为从i到>=n的期望值。
如果i有航班,dp[i] = dp[mark[i]];
如果有航班,dp[i] = sigma(dp[i+j]) / 6 + 1 ( 1<= j <=6)
代码:
思路:设dp[i] 为从i到>=n的期望值。
如果i有航班,dp[i] = dp[mark[i]];
如果有航班,dp[i] = sigma(dp[i+j]) / 6 + 1 ( 1<= j <=6)
代码:
#include<cstdio> #include<algorithm> #include<iostream> using namespace std; const int maxn = 100050; double dp[maxn]; int mark[maxn]; int n,m; void init(){ dp[0] = 0; fill(mark,mark+maxn,-1); fill(dp,dp+maxn,0); } int main(){ while(~scanf("%d%d",&n,&m)){ if(n + m == 0) break; init(); int a,b; while(m--){ scanf("%d%d",&a,&b); mark[a] = b; } for(int i=n-1;i>=0;i--){ if(mark[i] != -1) dp[i] = dp[mark[i]]; else{ double tmp = 0; for(int j=1;j<=6;j++) tmp += dp[i+j]; dp[i] = tmp / 6 + 1; } } printf("%.4f\n",dp[0]); } return 0; }
相关文章推荐
- centOS 6.5关闭防火墙步骤
- 淘宝分布式数据库是如何实现高可用的
- The model used to open the store is incompatible with the one used to create the store
- The model used to open the store is incompatible with the one used to create the store
- The file “XXX” couldn’t be opened because you don’t have permission to view it.
- The file “XXX” couldn’t be opened because you don’t have permission to view it.
- linux内核体验
- Linux运维系统工程师系列---25
- systemd在各个linux发行版的普及
- @property的参数说明
- 在 RHEL/CentOS 7.0 中安装 LAMP
- Linux 进程关系
- openfire每次启动都要在网页初始化设置的解决方法
- Photoshop技能167个经典的Photoshop技巧大全
- Photoshop技能167个经典的Photoshop技巧大全
- 每天一个Linux命令-1(grep)
- linux环境 mysql的安装与卸载
- [转][Linux]10个最酷的Linux单行命令
- Odoo(OpenERP)实施方法论
- Shell脚本实现批量生成nagios配置文件