HDU4336:Card Collector】的更多相关文章

题面 传送门 Sol 方法一 直接状压就好了 # include <bits/stdc++.h> # define RG register # define IL inline # define Fill(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; int n; double p[21], f[1 << 20]; int main(RG int argc, RG char *arg…
题意 有n张卡片,每一次 有pi的概率买到第i张卡.求买到所有卡的期望购买次数. n<=20 解析 Solution 1:大力状压(就是步数除以方案数) #include<iostream> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #define ll long long #define re…
[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…
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…
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 smart boy, you notice that to win t…
Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5254    Accepted Submission(s): 2676Special 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…
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 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…
题目链接: 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 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(期望+min-max容斥) Card Collector woc居然在毫不知情的情况下写出一个min-max容斥 题意 买一包方便面有几率附赠一张卡,有\(n\)种卡,每种卡出现的概率是\(p_i\),保证\(\Sigma p_i \le 1\),集齐所有种类卡牌期望买多少包方便面? 解法 看次题解前,你必须要理解当只有一种卡,他出现的概率是\(p\),那么我期望购买$\frac 1 p $包方便面就可以获得这种卡. 否则请你右上角,因为博主不会解释... 唯一的解…
题目链接 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…
容斥原理+状压 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…
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 smart boy, you…
题目链接 hdu4336 题解 最值反演 也叫做\(min-max\)容斥,在计算期望时有奇效 \[max\{S\} = \sum\limits_{T \in S} (-1)^{|T| + 1}min\{T\}\] 证明: 记\(S = \{a_i\}\),其中对于\(i < j\)有\(a_i < a_j\) 那么我们计算每一个\(a_i\)的贡献,有 \[ \begin{aligned} \sum\limits_{T \in S} (-1)^{|T| + 1}min\{T\} &=…
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 smart boy, you notice that to win t…
题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望值. 一开始,自己所理解的期望值是原来学过的  一个值*它自身发生的概率,这没错,但是不知道在这一题里面 那个值是多少 经过重重思考和挣扎最后明白了,这一题中,n就是那个值,也是你要求的,感觉理解这个好难,但是好重要, 此题中,将n设置为 dp[0] 可以这样想,你要买sum包,才能集齐n种卡片,那么 你最后…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要买的食品数的期望. 压缩DP:把每个食品用二进制表示,0和1分别表示没有卡片和已经收集到此卡片的期望,则 f[s]=(1-Σp[i])*f[s]+Σp[j]*f[s]+Σp[k]*f[s|(1<<k)] s表示状态,i表示所有卡片编号,j表示s状态中已经有的卡片编号,k表示s状态中没有的卡片编号…
题意 题目链接 \(N\)个物品,每次得到第\(i\)个物品的概率为\(p_i\),而且有可能什么也得不到,问期望多少次能收集到全部\(N\)个物品 Sol 最直观的做法是直接状压,设\(f[sta]\)表示已经获得了\(sta\)这个集合里的所有元素,距离全拿满的期望,推一推式子直接转移就好了 主程序代码: int N; double a[MAXN], f[MAXN]; signed main() { // freopen("a.in", "r", stdin);…
显然,这题有一种很简单的做法即直接状压卡牌的状态并转移期望的次数.但我们现在有一个更加强大的工具——min-max容斥. min-max 容斥(对期望也成立):\(E[max(S)] = \sum_{T\subseteq S}^{\ }(-1)^{|T| - 1}E[min(T)]\) 我们可以让 \(E[max(S)]\) 表示 \(S\) 中所有元素均出现的期望时间(即最后一个元素出现的期望时间),\(E[min(S)]\) 表示 \(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:…
题目传送门 题目描述 夏川的生日就要到了.作为夏川形式上的男朋友,季堂打算给夏川买一些生日礼物.商店里一共有种礼物.夏川每得到一种礼物,就会获得相应喜悦值$W_i$(每种礼物的喜悦值不能重复获得).每次,店员会按照一定的概率$P_i$(或者不拿出礼物),将第i种礼物拿出来.季堂每次都会将店员拿出来的礼物买下来.没有拿出来视为什么都没有买到,也算一次购买.众所周知,白毛切开都是黑的.所以季堂希望最后夏川的喜悦值尽可能地高.求夏川最后最大的喜悦值是多少,并求出使夏川得到这个喜悦值,季堂的期望购买次数…
http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:有n种卡片,一个包里会包含至多一张卡片,第i种卡片在某个包中出现的次数为pi,问将所有种类的卡片集齐需要买的包的期望. 注意存在某个包中一张也没有. 分析:状态压缩有个挺显然提示,N<=20,这是在次落落的在提示你. 我们首先定义: dp[st] 表示 st 状态到目标状态 的期望是多少 : st转化为二进制0表示当前状态没有这个bit的卡片 , 1表示当前状态有这个bit位的卡片; 然后有如下的…
题目传送门 https://vjudge.net/problem/HDU-4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 题解 minmax 容斥模板题. 一个集合 \(S\) 的至少有一个邮票出现的最早时间是 \(\frac 1{\sum\limits_{i\in S} p_i}\). 时间复杂度 \(O(2^n)\). #include<bits/stdc++.h> #define fec(i, x, y) (int i = head…
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 smart boy, you notice that to win t…
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…
三色算法,高效率垃圾回收,jvm调优 Garbage collector:垃圾回收器 What garbage? 没有任何引用指向它的对象 JVM GC回收算法: 引用计数法(ReferenceCounting) 给对象中添加一个引用计数器,每当有一个地方引用他时,计数器值就+1,:当引用失效时,计数器值就-1:任何时刻计数器为0的对象就是不可能在被使 优点:判定效率高 缺点:不会完全准确,因为如果出现两个对象相互引用的问题就不行了 很明显,到最后两个实例都不再用了(都等于null了),但是GC…