Codeforces 1156F Card Bag(概率DP)
设dp[i][j]表示选到了第i张牌,牌号在j之前包括j的概率,cnt[i]表示有i张牌,inv[i]表示i在mod下的逆元,那我们可以考虑转移,dp[i][j]=dp[i-1][j-1]*cnt[j]*inv[n-i+1],这个只是表示当前成功转移到i j的状态,如果要考虑胜利的条件,显然是选在选一次j即可赢取胜率,那么对于答案ans只需要加上dp[i-1][j-1]*cnt[j]*inv[n-i+1]*(cnt[j]-1)*inv[n-i]即可,因为我们这个dp[i][j]是记录j之前所有的概率和,需要开一个sum记录之前的和再去更新当前的dp[i][j]即可,记得初始化,所有dp[0][j]都是1,没有选那么概率显然为1,复杂度O(n^2),可以不需要开二维数组。
// ——By DD_BOND //#include<bits/stdc++.h>
#include<functional>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define MP make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lowbit(a) (a&(-a))
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
#define debug(x) cerr<<#x<<"="<<x<<"\n"; using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const ll LLMAX=2e18;
const int MOD=;
const double eps=1e-;
const int MAXN=1e6+; inline ll sqr(ll x){ return x*x; }
inline int sqr(int x){ return x*x; }
inline double sqr(double x){ return x*x; }
ll __gcd(ll a,ll b){ return b==? a: __gcd(b,a%b); }
ll qpow(ll a,ll n){ll sum=;while(n){if(n&)sum=sum*a%MOD;a=a*a%MOD;n>>=;}return sum;}
inline int dcmp(double x){ if(fabs(x)<eps) return ; return (x>? : -); } ll dp[][],inv[],cnt[]; int main(void)
{
ios::sync_with_stdio(false); cin.tie(); cout.tie();
inv[]=dp[][]=;
for(int i=;i<=;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
ll n,ans=; cin>>n;
for(int i=;i<=n;i++){
int x; cin>>x;
cnt[x]++;
dp[][i]=;
}
for(int i=;i<=n;i++){
ll sum=;
for(int j=;j<=n;j++){
ll p=dp[i-][j-]*cnt[j]%MOD*inv[n-i+]%MOD;
sum=(sum+p)%MOD;
dp[i][j]=sum;
if(cnt[j]>=) ans=(ans+p*(cnt[j]-)%MOD*inv[n-i]%MOD)%MOD;
}
}
cout<<ans<<endl;
return ;
}
Codeforces 1156F Card Bag(概率DP)的更多相关文章
- hdu4336 Card Collector(概率DP,状态压缩)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- hdu4336 Card Collector 概率dp(或容斥原理?)
题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望 ...
- HDU-4336 Card Collector 概率DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要 ...
- HDU4336 Card Collector (概率dp+状压dp)
http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:有n种卡片,一个包里会包含至多一张卡片,第i种卡片在某个包中出现的次数为pi,问将所有种类的卡片集齐 ...
- $HDU$ 4336 $Card\ Collector$ 概率$dp$/$Min-Max$容斥
正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\le ...
- BZOJ 3270 博物馆 && CodeForces 113D. Museum 期望概率dp 高斯消元
大前提,把两个点的组合看成一种状态 x 两种思路 O(n^7) f[x]表示在某一个点的前提下,这个状态经过那个点的概率,用相邻的点转移状态,高斯一波就好了 O(n^6) 想象成臭气弹,这个和那个的区 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- HDU 4336 Card Collector(动态规划-概率DP)
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...
随机推荐
- Python3学习笔记(十二):闭包
闭包定义: 在一个外函数中定义了一个内函数,内函数里引用了外函数的临时变量,并且外函数的返回值是内函数的引用.这样就构成了一个闭包. 我们先来看一个简单的函数: def outer(a): b = 1 ...
- 谷歌浏览器安装 socketLog
第一步(本地浏览器安装调试扩展) 下载扩展包并解压 链接:https://pan.baidu.com/s/14df0ewl_3wjRHc8H1jsrWQ提取码:yyu1 打开谷歌浏览器,地址栏输入 c ...
- 错误“Object reference not set to an instance of an object”的解决方法
在进行unity游戏制作的C#代码编写时,会遇到“NullReferenceException: Object reference not set to an instance of an objec ...
- python3笔记五:while语句
一:学习内容 while语句 while-else语句 while语句练习 二:while语句 1. 格式 while 表达式: 语句 2.逻辑 当程序执行到while语句时,首先计算表达式的值 ...
- 为EasyUI的dataGrid单元格增加鼠标移入移出事件
onLoadSuccess: function (data) { $(".datagrid-row").mouseover(function (e) { var text = $( ...
- ASP.NET postback with JavaScript (UseSubmitBehavior)
ASP.NET postback with JavaScript Here is a complete solution Entire form tag of the asp.net page < ...
- CEF3编译
要使用CEF3首先就要编译 下载网址为http://opensource.spotify.com/cefbuilds/index.html#windows64_builds 如果下载不动 可以用我上传 ...
- android studio中方法和类被调用多次,但是AS显示灰色,解决办法
Android Studio里面的一些类及方法,明明有被其他的类或者方法调用,但是去看的时候显示灰色,鼠标放上面的时候显示:Class ‘XXX’ is never used或者Method ‘XXX ...
- OpenStack 启动虚拟机 Booting from Hard Disk
问题 OpenStack 启动虚拟机 Booting from Hard Disk-GRUB 环境 OpenStack RUNNING IN vSphere 6.0.0 VM 开启了 CPU 虚拟化支 ...
- python3.6+RF连接mysql
接口自动化中会遇到有操作数据库的动作 目录 1.安装第三方库 2.安装pymysql 3.数据库操作 1.安装第三方库 使用在线安装:pip install robotframework_databa ...