题意:

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

  1. // #pragma comment(linker, "/STACK:102c000000,102c000000")
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <sstream>
  6. #include <string>
  7. #include <algorithm>
  8. #include <list>
  9. #include <map>
  10. #include <vector>
  11. #include <queue>
  12. #include <stack>
  13. #include <cmath>
  14. #include <cstdlib>
  15. // #include <conio.h>
  16. using namespace std;
  17. #define clc(a,b) memset(a,b,sizeof(a))
  18. #define inf 0x3f3f3f3f
  19. #define lson l,mid,rt<<1
  20. #define rson mid+1,r,rt<<1|1
  21. const int N = 2e5+;
  22. const int M = 1e6+;
  23. const int MOD = 1e9+;
  24. #define LL long long
  25. #define LB long double
  26. #define mi() (l+r)>>1
  27. double const pi = acos(-);
  28. const double eps = 1e-;
  29. void fre() {
  30. freopen("in.txt","r",stdin);
  31. }
  32. // inline int r() {
  33. // int x=0,f=1;char ch=getchar();
  34. // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
  35. // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
  36. // }
  37. int n,k;
  38. LB p[],ans[],f[<<];
  39. LB dp(int x){
  40. if(x==) f[x]=;
  41. LB tot=;
  42. int cnt=;
  43. for(int i=;i<=n;i++){
  44. if((x&(<<(i-)))==) tot+=p[i];
  45. else cnt++;
  46. }
  47. if(cnt>=k){
  48. if(cnt>k) return ;
  49. for(int i=;i<=n;i++){
  50. if(x&(<<(i-))) ans[i]+=f[x];
  51. }
  52. return f[x];
  53. }
  54. for(int i=;i<=n;i++){
  55. if((x&(<<(i-)))==){
  56. int t=x|(<<(i-));
  57. f[t]+=f[x]*(p[i]/tot);
  58. }
  59. }
  60. return f[x];
  61. }
  62. int main(){
  63. // fre();
  64. scanf("%d%d",&n,&k);
  65. int m=n;
  66. for(int i=;i<=n;i++){
  67. cin>>p[i];
  68. if(p[i]<=1e-)
  69. m--;
  70. }
  71. k=min(m,k);
  72. for(int i=;i<(<<n);i++) dp(i);
  73. for(int i=;i<=n;i++) printf("%.9lf ",(double)ans[i]);
  74. return ;
  75. }

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. socklen_t在windows和linux平台下的头文件定义

    windows平台下:头文件:#include<ws2tcpip.h> linux平台下:下面两个头文件都有定义:1)#include <sys/socket.h>2)#inc ...

  2. qtp与selenium2的区别

    QTP:  我觉得qtp适合的人: 对编程不是很熟悉的 厌烦了手动的功能测试,想快速进入自动化行业的 公司想快速自动化项目,并且对价格或者对盗版无所谓的 vbs脚本语言易于上手,可以培训你对代码的兴趣 ...

  3. android.content.Context 含义及使用

    Context字面意思上下文,位于framework package的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄,很多方法需要通过Con ...

  4. Ubuntu使用总结

    错误 鼠标闪烁解决 系统设置->显示—>未知显示器->关闭->应用->选择当前配置 提示sudo: unable to resolve host ,亦即无法解析主机. 原 ...

  5. 纯tarjan poj2186

    tarjan,叙叙旧咯 #include<cstdio>#define maxn 50005int e[maxn],ne[maxn],be[maxn],all;int DFN[maxn], ...

  6. Java I/O 扩展

    Java I/O 扩展 标签: Java基础 NIO Java 的NIO(新IO)和传统的IO有着相同的目的: 输入 输出 .但是NIO使用了不同的方式来处理IO,NIO利用内存映射文件(此处文件的含 ...

  7. U盘启动格式

    U盘的几种启动模式:USB-HDD.USB-ZIP.USB-HDD+.USB-ZIP+.USB-CDROM 1.  USB-HDD 硬盘仿真模式,DOS启动后显示C:盘,HP U盘格式化工具制作的U盘 ...

  8. Android ArrayAdapter 详解

    本文主要讲解ArrayAdapter的创建方法,我把ArrayAdapter分为三种:简单的.样式丰富的但内容简单的.内容丰富的. 默认的,ArrayAdapter期望接受的样式文件里只含有一个tex ...

  9. 关于python中使用mongodb模块,save和insert的小问题

    今天写python脚本的时候发现这样一个问题: import os , string , datetime ,pymongo; conn = pymongo.Connection("127. ...

  10. Windows下FFmpeg快速入门

    本系列文章导航 Windows下FFmpeg快速入门 ffmpeg参数解释 mencoder和ffmpeg参数详解(Java处理视频) Java 生成视频缩略图(ffmpeg) 使用ffmpeg进行视 ...