题目链接:https://cn.vjudge.net/problem/UVALive-8138 题意 有一个随机数生成器,输出1-n的整数. 现在已经输出了k个数,问再取几个数才能使取出的所有数的个数至少为2. 注意T<=1e5, \sum k<=1e5 思路 (听说存在公式?理论上说有了转移方程和边界,公式就是存在 概率dp,注意状态的选取. 设i为出现0次的数的个数,j为出现1次的数的个数. \[ \begin{align*} dp(i, j) &= \frac{i}{n}[dp(…
题意呢 就是有两种售票方式 一种是icpc 一种是其他方式 icpc抢票成功的概率是其他方式的2倍…… 这时 一个人出现了 他通过内幕知道了两种抢票方式各有多少人 他想知道自己如果用icpc抢票成功的概率是多少 用acm抢票成功的概率是多少…… 做过不多的概率dp 还在摸索…… dp[i][j]代表第i轮有j个icpc的人已经有票了…… 当然同时i-j个通过其他方式抢票的人也有票了 这就是用同样的函数搜两次的原理…… 优化一次i<=a 一次是把初始化放到for里…… 第一次见这么卡时间的题………
思路:定义DP方程dp[i][j]标记选到第i个巧克力的时候,桌面上还剩下j个巧克力,状态转移有两个方向,dp[i-1][j-1],dp[i-1]lj+1],分别表示桌面上多了一个和消了一个,乘上需要的概率即可. 注意:这个题目的输入量很大,所以需要优化,首先是n+m是奇数的时候,或者m > c的时候概率是0. 然后就是当n很大的时候,可以知道后面所加的概率越来越小,题目要求精确到三位小数,所以大约1500以后的值就不会影响答案了,可以直接去掉.如果没有这两个优化,很容易超时.dp过程并不难,难…
题目链接:http://vjudge.net/problem/viewProblem.action?id=24999 主要思想就是解方程的思想. 二维dp应该很容易想到,就是当前位置加队伍长度. dp递推式存在循环,因此想到像解方程组一样把一个dp值解出来,然后顺序递推. 先贴代码,一会把递推式放上来. #include <stdio.h> #include <stdlib.h> #include <cstring> #include <algorithm>…
题意:有n个人进行m次比赛,每次比赛有一个排名,最后的排名是把所有排名都加起来然后找到比自己的分数绝对小的人数加一就是最终排名. 给了其中一个人的所有比赛的名次.求这个人最终排名的期望. 思路: 渣渣的第一道概率DP...弱渣. dp[i][j]代表进行了i轮比赛之后得分为j的人数的期望,可以知道dp[i][j]来自于dp[i-1][j-m...j-1]的期望的人数乘以概率.这里就是前缀和,用树状数组进行优化... 但是要注意,转移的时候一定要排除已经知道的名次的影响,不能用已知名次来转移...…
The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms -). Now she…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Memory Limit: 128 M Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two ro…
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那么简练就过不了. 太坑了... 当然,说到底还是实力的问题,谁叫你不会一些常数级别的优化. 谁叫你写的时候不写的好一点. 比赛的时候在速度秒掉了最后两题后,卡这道题卡了4个多小时,也没有心情去看其他的题目了. 期间想了各种优化的方法. 最后因为一个小错误wa了N次后没有过而遗憾终身... 1. 直接…
传送门 简单概率dp. 显然每次转移的式子可以用一个矩阵表示出来: 这个是循环矩阵. 因此只用维护第一行快速幂一波就行了. 代码: #include<bits/stdc++.h> #define N 1005 using namespace std; int n,m,K,a[N]; double b[N]; struct Matrix{double val[N];}ans,tmp; inline Matrix operator*(Matrix a,Matrix b){ Matrix c; me…
题目链接 https://icpcarchive.ecs.baylor.edu/external/65/6514.pdf 题意:给出n个数(n<8) 求这n个数分别两个程序排成有序时,程序的期望迭代次数.排序程序如下. // Monty's Code while (!sorted(a)) { int i = random(n) ; int j = random(n) ; if (a[min(i,j)] > a[max(i,j)]) swap(a[i], a[j]) ; } //Carlos's…
Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2670    Accepted Submission(s): 921 Problem Description A crowd of little animals is visiting a mysterious laboratory…
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710606.html *************************************************************** 概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. 首先…
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且从当前光标删除到第一个出错的位置(留下的字符串要么为空,要么每个字符都是对的).问你,他正确的打完该字符串最少需要花费的时间的期望值是多少 字符串的长度小于等于3000 题意有点绕,具体可以看看原题是怎么描述的 做法分析 首先确定这是一个概率DP的问题. 定义状态 f[i] 表示正确的打完前 i 个…
wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402    Accepted Submission(s): 248 Special Judge Problem Description There are n grids in a row. The coordinates of grids are numbered fro…
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> typedef long long ll; using namespace std…
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description   One day, sssworld and DDD play games together, but there are some special rules in this games.They both have their own HP. Each round they dice respectively and…
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six…
题目链接:http://poj.org/problem?id=3744 简单的概率DP,分段处理,遇到mine特殊处理.f[i]=f[i-1]*p+f[i-2]*(1-p),i!=w+1,w为mine点.这个概率显然是收敛的,可以转化为(f[i]-f[i-1])/(f[i-1]-f[i-2])=p-1.题目要求精度为1e-7,在分段求的时候我们完全可以控制进度,精度超出了1e-7就不运算下去了.当然此题还可以用矩阵乘法来优化. 考虑概率收敛代码: //STATUS:C++_AC_0MS_164K…
Recently poet Mr. po encountered a serious problem, rumor said some of his early poems are written by others. This brought a lot of trouble to Mr. po, so one day he went to his best friend MasterO for help. MasterO handed over a small wooden box with…
所谓概率dp,用动态规划的思想找到一个事件中可能发生的所有情况,然后找到符合要求的那些情况数,除以总数便可以得到符合要求的事件发生的概率.其核心思想还是通过dp来得到事件发生的所有情况,很类似在背包专题中我们提及的组合记数问题. 我们通过具体的实例来体会概率dp这类问题.(Problem source : Light OJ 1064) Description n common cubic dice are thrown. What is the probability that the sum…
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…
好久之前学过,记得是一次亚洲区的前几天看了看概率dp,然后亚洲区就出了一道概率dp,当时虽然做上了,但是感觉有很多地方没懂,今天起早温习了一下,觉得很多地方茅塞顿开,果然学习的话早上效果最好了. 首先来看一道最基础概率dp 题意是,有一个软件,有s个子系统,会产生n种bug. 某个程序员一天能发现一个bug,这个bug是这n种bug中的一种,然后发生在某个子系统中. 问,找到所有的n种bug,且每个子系统都找到bug,这样所要的天数,的期望. 期望,可以分解成多个子期望的加权和,权为子期望发生的…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 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…
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1503    Accepted Submission(s): 1025 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids la…
Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then, the first team in the l…
LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 1864    Accepted Submission(s): 732 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help h…
Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4512   Accepted: 1988 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp…
引用自:http://hi.baidu.com/aekdycoin/item/be20a91bb6cc3213e3f986d3,有改动 题意: 已知D, 每次从[1,D] 内的所有素数中选择一个Ni, 如果D = 0(mod Ni), 那么D /= Ni,否则D不变(可以看成是每一轮 D/= GCD(D,Ni) ) 思路: 概率DP 令 dp[ i ] 表示 D = i 的时候的期望, 即从i 转移到1 的次数期望. 我们有 p = kcnt[ i ] / cnt[ i ]; kcnt[ i ]…
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.  As a…
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 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 ch…