Codeforces Round #363 (Div. 1) C. LRU
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的更多相关文章
- 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 ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- 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 ...
- Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧
题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...
- 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] ...
- Codeforces Round #363 (Div. 2)A-D
699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include< ...
随机推荐
- socklen_t在windows和linux平台下的头文件定义
windows平台下:头文件:#include<ws2tcpip.h> linux平台下:下面两个头文件都有定义:1)#include <sys/socket.h>2)#inc ...
- qtp与selenium2的区别
QTP: 我觉得qtp适合的人: 对编程不是很熟悉的 厌烦了手动的功能测试,想快速进入自动化行业的 公司想快速自动化项目,并且对价格或者对盗版无所谓的 vbs脚本语言易于上手,可以培训你对代码的兴趣 ...
- android.content.Context 含义及使用
Context字面意思上下文,位于framework package的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄,很多方法需要通过Con ...
- Ubuntu使用总结
错误 鼠标闪烁解决 系统设置->显示—>未知显示器->关闭->应用->选择当前配置 提示sudo: unable to resolve host ,亦即无法解析主机. 原 ...
- 纯tarjan poj2186
tarjan,叙叙旧咯 #include<cstdio>#define maxn 50005int e[maxn],ne[maxn],be[maxn],all;int DFN[maxn], ...
- Java I/O 扩展
Java I/O 扩展 标签: Java基础 NIO Java 的NIO(新IO)和传统的IO有着相同的目的: 输入 输出 .但是NIO使用了不同的方式来处理IO,NIO利用内存映射文件(此处文件的含 ...
- U盘启动格式
U盘的几种启动模式:USB-HDD.USB-ZIP.USB-HDD+.USB-ZIP+.USB-CDROM 1. USB-HDD 硬盘仿真模式,DOS启动后显示C:盘,HP U盘格式化工具制作的U盘 ...
- Android ArrayAdapter 详解
本文主要讲解ArrayAdapter的创建方法,我把ArrayAdapter分为三种:简单的.样式丰富的但内容简单的.内容丰富的. 默认的,ArrayAdapter期望接受的样式文件里只含有一个tex ...
- 关于python中使用mongodb模块,save和insert的小问题
今天写python脚本的时候发现这样一个问题: import os , string , datetime ,pymongo; conn = pymongo.Connection("127. ...
- Windows下FFmpeg快速入门
本系列文章导航 Windows下FFmpeg快速入门 ffmpeg参数解释 mencoder和ffmpeg参数详解(Java处理视频) Java 生成视频缩略图(ffmpeg) 使用ffmpeg进行视 ...