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< ...
随机推荐
- Android:数据存储之SQLite
Android在运行时集成了SQLite , 所以每个Android应用程序都可以使用SQLite数据库. 我们通过SQLiteDatabase这个类的对象操作SQLite数据库,而且不需要身份验证. ...
- C++:静态成员
3.7.1 静态数据成员对象是类的一个实例,每个对象都具有自己的数据成员.例如,学生类张三或李四都具有自己的学号,姓名和平均成绩.在实际使用时,常常还需要一些其他的数据项,比如学生人数.总成绩.平均成 ...
- 转response.sendRedirect()与request.getRequestDispatcher().forward()区别
JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳转,但是 ...
- Lua for windows中SciTe开启支持python的方法
打开Options-Open Global Options #import python的#去掉即可
- svn: E180001: Unable to open an ra_local session to URL问题解决方案
在使用Android Studio的SVN导入项目时,出现了: svn: E180001: Unable to open an ra_local session to URLsvn: E180001: ...
- WebClient+Fiddler2完美搭配下载远程页面信息
WebClient可以下载远程页面信息,这个大家应该都知道,核心代码如下: WebClient web = new WebClient(); string url = String.Format(&q ...
- UVa 10735 (混合图的欧拉回路) Euler Circuit
题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...
- Codeforces Round #273 (Div. 2)
A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...
- Android开发时提示Your project contains error(s),please fix them be
有次在使用eclipse写好Android的代码,代码没有报错.然后 想在AVD中运行测试时,总是会弹出错误框,提示信息为: “Your project contains error(s),pl ...
- [转载]ios入门篇 -hello Word(1)
温馨提示:,如果您使用移动终端阅读本篇文章,请连接wifi的情况下阅读,里面有大量图片,以免造成您不必要的损失. 潜水博客园很多年,闲来无事,聊一下自己的经历,语文不好(如有什么错别字,请您在下评 ...