题目链接: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的更多相关文章

  1. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  2. 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]= ...

  3. ZOJ 3329-One Person Game(概率dp,迭代处理环)

    题意: 三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号 ...

  4. ZOJ 3502 Contest <状态压缩 概率 DP>

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...

  5. zoj 3640 Help Me Escape (概率dp 递归求期望)

    题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest w ...

  6. ZOJ 3329 One Person Game 概率DP 期望 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 本题分数为0的概率不确定,所以不能从0这端出发. 设E[i]为到达成功所 ...

  7. zoj 3822(概率dp)

    ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Ju ...

  8. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  9. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  10. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

随机推荐

  1. c++内存中字节对齐问题详解

    一.什么是字节对齐,为什么要对齐?    现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特 定的内存地址 ...

  2. 分析java程序中cpu占用过高的线程

    http://blog.csdn.net/jgwei/article/details/12079147 http://hllvm.group.iteye.com/group/topic/38893 h ...

  3. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  4. POJ2348+博弈

    /* 博弈 关键态:较大数是较小数的2倍以上. */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  5. Android SlidingMenu的getSupportActionBar无法找到的解决

    getSupportActionBar()方法不能用 进入Library中的src下找到SlidingFragmentActivity.java,修改 public class SlidingFrag ...

  6. 好看的游戏soul calibur

    http://soulcalibur.fr/index.php?wiki/sophitia/ http://astuce-soluce.playfrance.com/index.php/Soul_Ca ...

  7. Git教程之分支管理之二

    分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息.如果要强制禁用Fast forward模式,Git就会在merge时生成一个 ...

  8. Git教程之撤销修改(7)

    自然,你是不会犯错的.不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行:

  9. 213. House Robber II

    题目: Note: This is an extension of House Robber. After robbing those houses on that street, the thief ...

  10. HDU1548——A strange lift(最短路径:dijkstra算法)

    A strange lift DescriptionThere is a strange lift.The lift can stop can at every floor as you want, ...