hdu 4336 Card Collector】的更多相关文章

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) 问题描述 In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that,…
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…
Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3407    Accepted Submission(s): 1665Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful…
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2711    Accepted Submission(s): 1277Special Judge Problem Description In your childhood, do you crazy for collecting the beaut…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡片.问你收集齐n种卡片,吃的期望零食数是多少? 状态压缩:f[mask],代表收集齐了mask,还需要吃的期望零食数. 打开包装,有3种情况,第一种:没有卡片,概率(1-sigma(p[i])) 第二种,在已知种类中:概率sigma(p[j]) 第三种,在未知种类中:p[k] 因此 f[mask]…
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include &…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现的元素的期望. #include<cstdio> #include<cstring> #include<algorithm> #define db double using namespace std; ,M=(<<)+; int n,ct[M],bin[N];…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 bzoj 4036 的简单版,Min-Max 容斥即可. 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef double db; ,xm=(<<)+; int n,bin[xn]; db p[xn],mn[xm]; ; ),s>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p[i],问你将n种卡片收集全,要买零食袋数的期望. 题解: 表示状态: dp[state] = expectation state表示哪些卡片已经有了 找出答案: ans = dp[0] 什么都没有时的期望袋数 如何转移: 两种情况,要么得到了一张新的卡片,要么得到了一张已经有的卡片或者啥都没有.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可以没有卡片. 问你集齐n种卡片所买方便面数量的期望. 题解: 状态压缩. 第i位表示手上有没有卡片i. 表示状态: dp[state] = expectation (卡片状态为state时,要集齐卡片还要买的方便面数的期望) 找出答案: ans = dp[0] 刚开始一张卡片都没有. 如何转移: now:…
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amazing award. As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste…
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由于得到每张卡片的状态不知道,所以用状态压缩,dp[i] 表示这个状态时,要全部收齐卡片的期望. 由于有可能是什么也没有,所以我们要特殊判断一下.然后就和剩下的就简单了. 另一个方法就是状态压缩+容斥,同样每个状态表示收集的状态,由于每张卡都是独立,所以,每个卡片的期望就是1.0/p,然后要做的就是要去重,既然…
dp+状态压缩 #include<cstdio> using namespace std; ]; <<]; int main() { int n; while(scanf("%d",&n)!=EOF) { ; i<n; i++) scanf("%lf",&p[i]); dp[(<<n)-]=; <<n)-; i>=; i--) { dp[i]=1.0; double sum=0.0; ; j…
读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector>…
题意:要收集n种卡片,每种卡片能收集到的概率位pi,求收集完这n种卡片的期望.其中sigma{pi} <=1; 思路:容斥原理.就是一加一减,那么如何算期望呢.如果用二进制表示,0表示未收集到,1表示收集到. 那么1/p1(p1表示的是事件1发生的概率)表示的是1发生的期望,这边包括001,011,111,101 同理,1/p2包括的是010,011,111,110 1/p3:100,101,111,110 我们知道如果一件事发生的概率为pi,那么第一次发生这件事次数期望为1/pi. 同理,a和…
传送门 解题思路 第一种方法是状压\(dp\),设\(f(S)\)为状态\(S\)到取完的期望步数,那么\(f(S)\)可以被自己转移到,还可以被\(f(S|(1<<i))\)转移到,\(i\)为\(S\)中没有的一个元素. 第二种方法是\(Min-Max\)反演,要求的其实就是\(max(S)\),反演得\(max(S)=\sum\limits_{T\subseteq S}min(T)\),而\(min(T)=\sum p(i)\)(\(i\)是\(T\)的子集). 代码 状压 #inclu…
正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\leq 20$,那不就,显然考虑状压$dp$? 转移也很$easy$鸭,设$f_{s}$表示已经获得的卡片状态为$s$时候的期望次数 不难得到转移方程,$f_s=\sum_{i\notin{S}}f_{s|\{i\}}\cdot p_i+(1-\sum_{i\notin{S}}p_i)\cdot f_s…
题意:每包干脆面可能开出卡或者什么都没有,一共n种卡,每种卡每包爆率pi,问收齐n种卡的期望 思路:期望求解公式为:$E(x) = \sum_{i=1}^{k}pi * xi + (1 - \sum_{i = 1}^{k}pi) * [1 + E(x)]$,即能转换到x情况的期望+x情况原地踏步的期望. 因为n比较小,我们可以直接状压来表示dp[x]为x状态时集齐的期望.那么显然dp[111111111] = 0.然后我们状态反向求解.最终答案为dp[0]. 然后来看期望的求解:$E(x) =…
容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1940    Accepted Submission(s): 907Special Judge Problem Description In your childhood, do you crazy for collecting the bea…
http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:n张卡片,每一次取一个盒子,盒子里装有卡片i的概率是p[i],求得到所有卡片所需要开的盒子的期望数(n<=20) #include <cstdio> #include <cstring> using namespace std; const int N=22; int n; double p[N], f[1<<N]; int main() { while(~scan…
概率DP的题目,一直就不会做这类题目.dp[s]表示状态为s的时候再买多少张牌可以买全,表示的是一个期望值.dp[s] = 1 + P(empty) * dp[s] + P(had) * dp[s] + P(new) * dp[nst].从而可以解dp[s]. /* 4336 */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queu…
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge 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 i…
Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3001    Accepted Submission(s): 1435Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful…
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1708 Accepted Submission(s): 780 Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful cards…
题解: 之前听说过这个东西但没有学 令$max(S)$表示S中编号最大的元素,$min(S)$表示编号中最小的元素 $$max(S)=\sum{T \in S} {(-1)}^{|T|+1} min(T) $$ $$min(S)=\sum{T \in S} {(-1)}^{|T|+1} max(T) $$ 然后再在外面套个期望 $$E(max(S))=\sum{T \in S} {(-1)}^{|T|+1} E(min(T))$$ hdu 4336 定义大小比较为出现时间早晚 $E(max(S)…
hdu 4336 小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片.每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数量的期望是多少. 对于每袋食品.有两种结果,该卡片已经收集到了和没有收集到(没有卡片的情况视为收集到了). 把已经收集到的卡片的集合记为 s ,dp[s] 表示已经收集到集合s的卡片情况下收集齐全部的卡片的购买数量的期望,s 为空集即为所求.s  为全集时dp[s] = 0; 对于上面说的两种情况 _si…
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28903    Accepted Submission(s): 11789 Problem Description Many years ago , in Teddy's h…
[HDU4336]Card Collector(Min-Max容斥) 题面 Vjudge 题解 原来似乎写过一种状压的做法,然后空间复杂度很不优秀. 今天来补一种神奇的方法. 给定集合\(S\),设\(max\{S\}\)为\(S\)中的最大值,\(min\{S\}\)为集合\(S\)中的最小值. 那么我们可以得到: \(max\{S\}=\sum_{T\subseteq S}(-1)^{|T|+1}min\{T\}\) 证明的话,大概就是如果你钦定一个最小值,并且它强制出现, 如果枚举所有子集…
[HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+1)/(\sum p[j])\) 直接枚举一下即可 #include<cstdio> int n; float f[1<<20],p[20]; int main() { while(scanf("%d",&n)!=EOF) { for(int i=0;i&l…
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 1005 using namespace std; int v[nmax],w[nmax],dp[nmax]; int main() { //freopen("in…