BZOJ 2784 时间流逝
BZOJ 2784 时间流逝
古典概率论...
可以发现由于能量圈数量限制,所以所构成的必定为树状结构(即便是转成最小能量圈和能量圈权值和之后存在重复状态,但是每个状态的含义不同,而且不能自身转移自身就没有问题,而且每个重复状态的本质是相同的)。
那么很显然,可以看作树上高斯消元解决。
剩下的就模板了.jpg
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
struct Segment
{
double k,b;
Segment(){}
Segment(double x,double y){k=x,b=y;}
Segment operator + (const Segment &a) const {return Segment(k+a.k,b+a.b);}
Segment operator * (const double &a) const {return Segment(k*a,b*a);}
}f[55][55];
int n,T,a[55],vis[55][55];double p;
Segment dfs(int s,int x)
{
if(s>T)return Segment(0,0);if(vis[s][x])return f[s][x];vis[s][x]=1;
Segment ret=Segment(0,0);
double np=s?p:0,nq=(1-np)/x;
for(int i=1;i<=x;i++)ret=ret+dfs(s+a[i],i);
return f[s][x]=Segment(np/(1-nq*ret.k),(ret.b*nq+1)/(1-nq*ret.k));
}
int main()
{
while(scanf("%lf%d%d",&p,&T,&n)==3)
{
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);memset(vis,0,sizeof(vis));
printf("%.3lf\n",dfs(0,n).b);
}
}
BZOJ 2784 时间流逝的更多相关文章
- bzoj 2784 时间流逝 —— 树上高斯消元
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2784 其实转移是一棵树,从根到一个点表示一种能量圈状态,当能量值大于 T 是停止,也就是成为 ...
- bzoj 2784 [JLOI2012]时间流逝——树上高斯消元
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2784 一个状态可以加很多个能量圈,但减少能量圈的情况只有一种.所以可以用树来刻画. 然后就变 ...
- bzoj 2784: [JLOI2012]时间流逝【树形期望dp】
来自lyd课件 发现s和last(s),next(s)成树结构,然后把式子化简成kx+b的形式,做树形dp即可 #include<iostream> #include<cstdio& ...
- BZOJ2784: [JLOI2012]时间流逝
BZOJ2784: [JLOI2012]时间流逝 https://lydsy.com/JudgeOnline/problem.php?id=2784 分析: 挺有意思的一道题. 注意到状态数是\(P( ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
- bzoj 4610 Ceiling Functi
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
随机推荐
- vue-cli脚手架之webpack.prod.conf.js
webpack.prod.conf.js 生产环境配置文件: 'use strict'//js严格模式执行 const path = require('path')//这个模块是发布到NPM注册中心的 ...
- 关于Bootstrap fileinput 上传新文件,移除时触发服务器同步删除的配置
在Bootstrap fileinput中移除预览文件时可以通过配置initialPreviewConfig: [ { url:'deletefile',key:fileid } ] 来同步删除服务器 ...
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL,spring获取context
今天学习spring项目的时候出现了下面的错误信息: java.lang.ClassNotFoundException: org.springframework.web.context.Context ...
- mysql的varchar字段可以存储多少个中文字符
创建数据库,并创建一张表mytb进行测试 ******************************************************************************* ...
- python并发编程之线程
操作系统线程理论 参考资料:http://www.cnblogs.com/Eva-J/articles/8306047.html 线程和python 理论知识 全局解释器锁GIL Python代码的执 ...
- Spark编译
Spark的运行版本使用mvn编译,已经集成在源码中.如果机器有外网或者配置了http代理,可以直接调用编译命令来进行编译. windows&Linux命令如下: ./build/mvn \ ...
- tkinter中button按钮控件(三)
button控件 简单的实现: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry(" ...
- 第七章 鼠标(CHECKER1)
CHECKER1程序将客户区划分成25个矩形,构成一个5*5的数组.如果在其中一个矩形内单击鼠标,就用X形填充该矩形.再次单击,则X形消失. /*--------------------------- ...
- 【PAT】B1070 结绳(25 分)
此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...
- LInux下(centos7.2)更新 python3.7
进入超级管理员目录 su root 下载 wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz 找到下载的文件解压 tar - ...