Hdu 5346 MZL's game 2015ACM多校对抗赛第五场

来源:互联网 发布:笛子软件下载 编辑:程序博客网 时间:2024/05/16 05:11

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=5346

MZL's game

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 62    Accepted Submission(s): 44


Problem Description
MZL has n cute boys.They are playing a game♂.The game will run in turn
First,System choose an alive player x randomly.Player x will be out of the game.
Then player x will attack all alive players in the game
When a player is attacked,1p is the probability of he still lives,p is the probability of he dies
Now mzl wants to know:the probability of one player be out of the game and be attacked k times

You need to print the probability mod 258280327 for every k from 0 to n-1

According to Fermat Theory,xy mod 258280327=x*(y258280325) mod 258280327

p will be given in a special way
 

Input
The first line of the input contains a single number T, the number of test cases.
Next T lines, each line contains three integer n,x,y.p=xy
T5n2103 0x109 x+1y109.
It is guaranteed that y and 258280327 are coprime.
 

Output
T lines, every line n numbers: the ans from 0 to n-1
 

Sample Input
23 33 1009 23 233
 

Sample Output
172186885 210128265 223268793229582513 70878931 75916746 175250440 21435537 57513225 236405985 111165243 115953819
Hint
for case 1: The probability of you live and not be attacked is 1/3 The probability of you live and be attacked for one time is: (2/3)*(0.33*0.67+0.67*0.67*(1/2))=8911/30000
 

Source
2015 Multi-University Training Contest 5
 

题意:
n个可爱的人在玩游戏,每一次系统随机选择一个活着 的人出局,并攻击其余的人,每个人受到攻击,有p的概率会死亡,(1-p)的概率会存活下来。然后,下一轮n-1个人重复这个游戏。(T_T死了的人仍在该轮中,还会被扁丝~~)
求一个人受到k次攻击并出局的概率
做法:
给n个人编号1-n,假设系统依次选择1,2,3,,,,出局(当然也要是活着才能被选择出局)
那么dp[i][j]表示第i编号受到j次攻击后出局的概率,转移分两种情况考虑,第j次攻击来自第i-1编号人和来自第i-1编号前面的人。
那么,第一种情况,第i-1编号存活下来了才能被选择出局然后去攻击第i个人,那么此人受到的攻击次数就是j-1次了;
第二种情况,第i-1编号人死了,要不然第j次攻击一定来自第i-1编号的人,此人受到的攻击次数和i一样,都是j次。(因为我固定了出局顺序!!!)
所以,转移方程:dp[i][j]=dp[i-1][j-1]*p1+dp[i-1][j]*p2
p1表示第i-1编号受j-1次攻击存活的概率,p2表示第i-1编号受j次攻击死亡的概率

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define LL long long#define MOD 258280327LL power(LL x,LL k){    LL res=1;    while(k){        if(k&1)res=res*x%MOD;        x=x*x%MOD;        k>>=1;    }    return res;}LL dp[2100][2100];int main(){    LL n,x,y,T;scanf("%lld",&T);    while(T--){        scanf("%lld%lld%lld",&n,&x,&y);        LL dead=x*power(y,MOD-2)%MOD;//dead probability of an attack        LL live=(MOD+1-dead)%MOD;//live probability of an attack        dp[1][0]=1;        for(int j=1;j<n;j++)dp[1][j]=0;        for(int i=2;i<=n;i++){// i th peolivee            dp[i][0]=0;            LL tmp=1;            for(int j=1;j<i;j++){// j times attacked                //move = i th live (live^(j-1)) + i th dead (1-live^(j))                dp[i][j]=dp[i-1][j-1]*tmp%MOD+dp[i-1][j]*(MOD+1-tmp*live%MOD)%MOD;                tmp=tmp*live%MOD;            }        }        for(int k=0;k<n;k++){            LL tmp=1;            LL ans=0;            for(int i=1;i<=n;i++){                if(i-1<k)tmp=tmp*live%MOD;                ans=(ans+dp[i][k])%MOD;            }            // ans*live^(k)/n            ans=ans*tmp%MOD*power(n,MOD-2)%MOD;            printf("%lld%c",ans,k==n-1?'\n':' ');        }    }    return 0;}



0 0
原创粉丝点击