ZOJ-3593 One Person Game 概率DP
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593
带环的概率DP一般的做法是求出转移方程,然后高斯消元解方程。但是这里的环比较特殊,都是指向f[0]。
此题的转移方程为:f[i]=Σ(f[i+k]*p[k])+f[0]*p[0]+1.
我们可以设 f[i]=A[i]*f[0]+B[i].带入右边有:
f[i]=Σ(A[i+k]*f[0]*p[k]+B[i+k]*p[k])+f[0]*p[0]+1.
-> f[i]=Σ(A[i+k]*p[k]+p[0])*f[0]+B[i+k]*p[k]+1.
可以得到A[i]=A[i+k]*p[k]+p[0],B[i]=B[i+k]*p[k]+1,退出A[0]和B[0]就可以得到f[0]了。
//STATUS:C++_AC_0MS_196KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e30;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End double p[];
double A[N],B[N];
int T,n; int main(){
// freopen("in.txt","r",stdin);
int i,j,k;
int k1,k2,k3,a,b,c;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a,&b,&c);
mem(p,);
for(i=;i<=k1;i++){
for(j=;j<=k2;j++){
for(k=;k<=k3;k++){
if(i==a && j==b && k==c)p[]=;
else p[i+j+k]+=;
}
}
}
for(i=;i<=k1+k2+k3;i++)p[i]/=k1*k2*k3;
for(i=n;i>=;i--){
A[i]=p[],B[i]=;
for(j=;j<=k1+k2+k3 && i+j<=n;j++){
A[i]+=A[i+j]*p[j];
B[i]+=B[i+j]*p[j];
}
} printf("%.15lf\n",B[]/(-A[]));
}
return ;
}
ZOJ-3593 One Person Game 概率DP的更多相关文章
- zoj 3640 Help Me Escape 概率DP
记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- zoj 3329 One Person Game 概率DP
思路:这题的递推方程有点麻烦!! dp[i]表示分数为i的期望步数,p[k]表示得分为k的概率,p0表示回到0的概率: dp[i]=Σ(p[k]*dp[i+k])+dp[0]*p0+1 设dp[i]= ...
- ZOJ 3329-One Person Game(概率dp,迭代处理环)
题意: 三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号 ...
- ZOJ 3502 Contest <状态压缩 概率 DP>
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...
- zoj 3640 Help Me Escape (概率dp 递归求期望)
题目链接 Help Me Escape Time Limit: 2 Seconds Memory Limit: 32768 KB Background If thou doest w ...
- ZOJ 3329 One Person Game 概率DP 期望 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 本题分数为0的概率不确定,所以不能从0这端出发. 设E[i]为到达成功所 ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- zoj 3822 Domination (概率dp 天数期望)
题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
随机推荐
- CSS文件和Javascript文件的压缩
像JQuery一样来压缩我们的CSS和JS 我们都知道一般JQuery新版本发布的时候往往会有几个不同类型文件,比如原始版本文件.最小文件以及其他配合IDE智能提示的各种版本文件,前期我们使用JQue ...
- 动态链接库中分配内存引起的问题-- windows已在XX.exe中触发一个断点
动态链接库中分配内存引起的 本文主要是探讨关于在动态链接库分配的内存在主程序中释放所产生的问题,该问题是我在刚做的PJP工程中所遇到的,由于刚碰到之时感动比较诡异(这也是学识不够所致),所以将它写下来 ...
- 学点PYTHON基础的东东--数据结构,算法,设计模式---单向链表
看来看来,还是以下这个实现最优雅.. 其它的,要么NODE冗余,要么初始化丑陋... #!/usr/bin/env python # -*- coding: utf-8 -*- class Node: ...
- 玩转redis
http://www.cnblogs.com/huangxincheng/p/5002794.html
- 174. Dungeon Game
题目: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dung ...
- 使用PHP处理POST上传时$_FILES数组为何为空
在做一个简单的表单上传测试时,服务端的php脚本中,$_FILES数组为空;这样就不能获取从浏览器上传的信息.什么原因呢? 通过Google,找到下面这个web: php上传文件$_FILES数组为空 ...
- PHP array_chunk() 函数
今天在CSDN上,看到了一个问题 一维数组 PHP code array('0'=>'a',1=>'b',2=>'c',3=>'d',4=>'e',5=>'f' ...
- 【HDOJ】4775 Infinite Go
其实是一道模拟题,并查集用来优化.还可以的一道题目. /* 4775 */ #include <iostream> #include <sstream> #include &l ...
- git log
http://git-scm.com/book/zh/v2 https://backlogtool.com/git-guide/tw/contents/ http://gitbook.liuh ...
- Java面试题-多线程
1. java中有几种方法可以实现一个线程? 多线程有两种实现方法,分别是继承Thread类与实现Runnable接口. 这两种方法的区别是,如果你的类已经继承了其它的类,那么你只能选择实现Runna ...