zoj 3299 概率dp

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329

回头重推式子

题解:http://blog.csdn.net/morgan_xww/article/details/6775853#reply

学到:

1、目前做的两道期望的状态转移方程都是从大向小推,定义方式:dp[i][j][k]....  满足i,j,k时,要达到upbound(i),upbound(j),upbound(k),需要XX的期望

2、待定系数的方法

3、算pk的代码:

这里做个注释:

p[i+k+j]=sigma(v1*v2*v3/(k1+k2+k3)),然后就能理解那个代码了吧。

4、求状态转移方程关键还是找到一个当前状态与其他状态的关系等式,,,,目前经验不足,继续刷题吧

5、printf("%.15lf",)-----------哇靠,第一次见到这种写法,而且不这么些精度还不够

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define reped(i,s,e) for(int i=s;i>=e;i--)
#define arclr(aa,v) memset(aa,v,sizeof(aa));

const int MAXN = 500+30;

int A,B,c,k1,k2,k3,n;
double a[MAXN],b[MAXN],p[MAXN],e[MAXN];

void calp(int k1, int k2, int k3)
{
    memset(p,0,sizeof(p));
    //这个p的算法很不错啊
    p[0]=1.0/(k1*k2*k3);
    repe(i,1,k1)
        repe(j,1,k2)
            repe(k,1,k3)
            {
                if(i==A && j==B && k==c)continue;
                p[i+k+j]+=p[0];
            }
    //p[k1+k2+k3]=p[0];
}

double solve()
{
    e[n+1]=a[n+1]=b[n+1]=0;
    arclr(a,0);
    arclr(b,0);
    int en=k1+k2+k3;
    for(int i=n;i>=0;i--)
    {
        for(int k=3;k<=en;k++)
        {
            a[i]+=p[k]*a[i+k];
            b[i]+=p[k]*b[i+k];
        }
        a[i]+=p[0];
        b[i]+=1;
    }
    return b[0]/(1.0-a[0]);
}

int main()
{
    //freopen("zoj3299.txt","r",stdin);
    int ncase;
    scanf("%d",&ncase);
    while(ncase--)
    {
        scanf("%d%d%d%d%d%d%d", &n, &k1, &k2,&k3, &A, &B, &c);
        calp(k1,k2,k3);
        printf("%.15lf\n",solve());
    }
    return 0;
}

zoj 3299 概率dp

时间: 2024-10-10 09:45:04

zoj 3299 概率dp的相关文章

zoj 3640 概率dp

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him. And Cai

zoj 3329 概率dp

看了这么多,也就是个递推 1 /* 2 ZOJ 3329 3 题意:有三个骰子,分别有k1,k2,k3个面. 4 每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和. 5 当分数大于n时结束.求游戏的期望步数.初始分数为0 6 7 设dp[i]表示达到i分时到达目标状态的期望,pk为投掷k分的概率,p0为回到0的概率 8 则dp[i]=∑(pk*dp[i+k])+dp[0]*p0+1; 9 都和dp[0]有关系,而且dp[0]就是我们所求,为常数 10 设dp[i]=A

zoj 3822概率dp

Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboard with N r

zoj 3329 概率dp 环

一个游戏,你手上有三个骰子,分别有k1, k2, k3面.每次投出这三个骰子,得到三个面x, y, z.并且你有一个计数器,如果投出a, b, c, 则计数器归零,否则计数器加上三面之和,计数器初始为零.如果计数器的值大于 n 则游戏胜利.求胜利所需投骰子次数的期望. 以计数器的值为状态,dp[i] 表述计数器的值为i的情况下投骰子的期望.得到转移方程 p[k] 表示投出点数总和为k的概率,k=0时表示投出计数器归零的概率. dp[i] = p[0]*dp[0] + Σ(dp[i+k]*p[k]

zoj 3822 概率dp

1 /* 2 题目大意:一个n*m的棋盘,每天放一个棋子,每行每列至少有一个棋子时结束.求达到每行每列至少有一个棋子的天数的数学期望. 3 */ 4 #include <iostream> 5 #include <cstdio> 6 #include <cstring> 7 using namespace std; 8 9 const int maxn=55; 10 double dp[maxn*maxn][maxn][maxn];//放i颗棋子,j行有棋子,k列有棋子

zoj 3735 概率dp

Josephina and RPG Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of characters in a fictional setting. Players take responsibil

ZOJ 3551 Bloodsucker (概率DP)

ZOJ Problem Set - 3551 Bloodsucker Time Limit: 2 Seconds      Memory Limit: 65536 KB In 0th day, there are n-1 people and 1 bloodsucker. Every day, two and only two of them meet. Nothing will happen if they are of the same species, that is, a people

【概率DP】 ZOJ 3380 Patchouli&#39;s Spell Cards

通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率 * 设 dp[i][j]表示用前i个数,填充j个位置的方案数(要符合没有L个位置是一样的数) * dp[i][j]=dp[i-1][j]+Sigm( dp[i-1][j-k]*C[m-(j-k)][k] ) k<=j&&k<L * 其实就是看第i个数,可以不填,填一个位置,两个位置······这样累加过来. * 那么最后的答案就是

[ACM] ZOJ 3329 One Person Game (概率DP,有环,巧妙转化)

One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces. All the