LightOJ-1265-Island of Survival (概率dp)
来源:互联网 发布:淘宝装修市场 编辑:程序博客网 时间:2024/05/21 10:51
题目链接:LightOJ-1265-Island of Survival
考虑到五种情况,得出状态转移方程:
不过代码T了。。
#include<bits/stdc++.h>using namespace std;double dp[1007][1007];const double eps=1e-12;int main(){ int T; scanf("%d",&T); for(int kase=1;kase<=T;kase++) { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<=m;i++) dp[0][i]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { double fm=1; fm-=j*(j-1)*1.0/(i+j+1)/(i+j); double ans=0; if(j>=1) ans+=2*j*i*dp[i][j-1]/(i+j+1)/(i+j); if(i>=2) ans+=i*(i-1)*dp[i-2][j]/(i+j+1)/(i+j); if(j>=1) { double t=ans+2*j*dp[i][j-1]/(i+j+1)/(i+j); ans=max(t/fm,ans/(fm-2.0*j/(i+j+1)/(i+j))); } dp[i][j]=ans; } } printf("Case %d: %.15f\n",kase,dp[n][m]); } return 0;}
还有一种方法就是观察题目可以发现若没有虎,则必存活,若虎的数量为奇数,必死亡,若虎的数量是偶数。则忽略鹿的数量(鹿对游戏不产生影响),每次选取两只虎的概率是
#include<bits/stdc++.h>using namespace std;int main(){ int T; scanf("%d",&T); for(int kase=1;kase<=T;kase++) { int n,m; scanf("%d%d",&n,&m); if(n==0) printf("1.0000000000000\n"); else if(n%2==1) puts("0.00000000000000"); else { double ans=1; while(n) { ans*=(n-1.0)/(n+1.0); n-=2; } printf("%.15f\n",ans); } }}
0 0
- LightOJ 1265 Island of Survival(概率DP)
- 【LightOJ 1265】Island of Survival(概率DP)
- LightOJ 1265 Island of Survival(概率DP)
- LightOJ-1265-Island of Survival (概率dp)
- [LightOJ 1265] Island of Survival (概率)
- lightoj 1265 Island of Survival 概率
- [LightOJ 1265 Island of Survival ]数学、概率
- light oj 1265 - Island of Survival(概率dp)
- LightOJ - 1265 Island of Survival 脑洞 概率DP 1月3日
- LIGHTOJ 1265 - Island of Survival [递推|概率dp]【杂类|动态规划】
- lightoj 1265 Island of Survival
- LightOJ 1265 Island of Survival
- LightOJ1265---Island of Survival (概率dp)
- Island of Survival LightOJ
- Island of Survival LightOJ
- Island of Survival LightOJ
- LightOJ - 1265 Island of Survival 期望
- 7.22 A lightoj 1265 Island of Survival
- 如何portingADSP中的sensor
- 程序员的故事
- 使用git码云为unity版本控制1
- hdu 1698 Just a Hook(线段树)
- Java sdut acm 3869购物车
- LightOJ-1265-Island of Survival (概率dp)
- 2017.4.21 2^k进制数 思考记录
- 对所提取的ip进行有效性检测
- 内连接(inner join)
- eclipse Java 运行环境配置之添加已安装的 JRE(Java Runtime Environment)
- textile 自定义文本格式
- Java核心技术II:为多个客户端服务
- 链表的有序集合
- 利用session实现用户登录