题意:

n个数,长度为k的缓存,每次询问,每个数以pi的概率被选,如果不在缓存区则加入,如果缓存区满了,则第一个进缓存的出来,问10^100次询问以后每个数在缓存的概率

思路:

状压DP,看了hzwer的代码

f[x]表示当前状态为x的概率

枚举不在缓存区的数:f[t]+=f[x]*(p[i]/tot);  t=x|(1<<(i-1)); tot是当前状态情况下,不在缓存区的所有概率

如果缓存区数大于k,则当前状态概率为0

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = 2e5+;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int n,k;
LB p[],ans[],f[<<];
LB dp(int x){
if(x==) f[x]=;
LB tot=;
int cnt=;
for(int i=;i<=n;i++){
if((x&(<<(i-)))==) tot+=p[i];
else cnt++;
}
if(cnt>=k){
if(cnt>k) return ;
for(int i=;i<=n;i++){
if(x&(<<(i-))) ans[i]+=f[x];
}
return f[x];
}
for(int i=;i<=n;i++){
if((x&(<<(i-)))==){
int t=x|(<<(i-));
f[t]+=f[x]*(p[i]/tot);
}
}
return f[x];
}
int main(){
// fre();
scanf("%d%d",&n,&k);
int m=n;
for(int i=;i<=n;i++){
cin>>p[i];
if(p[i]<=1e-)
m--;
}
k=min(m,k);
for(int i=;i<(<<n);i++) dp(i);
for(int i=;i<=n;i++) printf("%.9lf ",(double)ans[i]);
return ;
}

Codeforces Round #363 (Div. 1) C. LRU的更多相关文章

  1. Codeforces Round #363 (Div. 2)E. LRU

    E. LRU time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  2. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  3. Codeforces Round #363 (Div. 2)

    A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...

  4. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  5. Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环

    题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...

  6. Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集

    题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...

  7. Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧

    题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...

  8. Codeforces Round #363 (Div. 2) C. Vacations —— DP

    题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...

  9. Codeforces Round #363 (Div. 2)A-D

    699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include< ...

随机推荐

  1. C++:友元(非成员友元函数、成员友元函数、友元类)

    3.8  友元:友元函数和友元类 友元函数 :既可以是不属于任何类的非成员函数,也可以是另一个类的成员函数,统称为友元函数.友元函数不是当前类的成员函数,而是独立于类的外部函数,但它可以访问该类所有的 ...

  2. 面试题_103_to_124_关于 OOP 和设计模式的面试题

    这部分包含 Java 面试过程中关于 SOLID 的设计原则,OOP 基础,如类,对象,接口,继承,多态,封装,抽象以及更高级的一些概念,如组合.聚合及关联.也包含了 GOF 设计模式的问题. 103 ...

  3. js 返回的数据类型 5类

    对变量或值调用 typeof 运算符将返回下列值之一: undefined - 如果变量是 Undefined 类型的 boolean - 如果变量是 Boolean 类型的 number - 如果变 ...

  4. HighCharts 饼图

    @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } @section ...

  5. UVa 1636 (概率) Headshot

    既然是第一道概率题,就正儿八经地分析一下吧. 题意: 有一个左轮枪,里面随机装了或者没装子弹,用一个01序列表示.现在已知扣动第一次扳机没有子弹,问是继续扣动扳机还是随机转动一下再扣,那种选择使得第二 ...

  6. WebView点击加载的页面中的按钮时不弹出新窗口以及在加载后执行javascript

    mWebView.setWebViewClient(new WebViewClient() { //点击网页中按钮时,在原页面打开 public boolean shouldOverrideUrlLo ...

  7. fmri当前相关软件工具整理

    1.spm; 2.afni; 3.fsl; 4.drtools; 5.prtools; 6.phycaa+; 7.cca-fmri;

  8. mysql教程-触发器

    触发器 1. mysql触发器 情景说明 情景设置,如图,当我们点击了购买,将会发生什么? 现有如下两张表 商品表 编号(id)名称(name)价格(price)库存(stock) 1F2战斗机100 ...

  9. HDU 1247 Hat’s Words

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  10. webservice-WebService试题

    ylbtech-doc:webservice-WebService试题 WebService试题 1.A,返回顶部 001.{WebService题目}下列是Web服务体系结构中的角色的是()(选择3 ...