[Codeforces-div.1 167B] Wizards and Huge Prize

试题分析

注意到每个物品互相独立,互不干扰之后就非常好做了。

算出一个物品最后的价值期望,然后乘以K即可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm> using namespace std;
#define LL long long inline int read(){
int x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF = 2147483600;
const int MAXN = 100010; int N,K; double f[2][MAXN+1]; int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
N=read(),K=read();
//for(int j=1;j<=N+1;j++) f[N&1][j]=0;
for(int i=N-1;i>=0;i--){
int x=(i&1),y=(x^1);
//for(int j=1;j<=N;j++) f[x][j]=0;
for(int j=1;j<800;j++)
f[x][j]=(f[y][j+1]+j)/(1.0*K*(j+1))+
1.0*j*(f[y][j]+(1.0*(j+1)/2.0))/(1.0*K*(j+1))+
(1.0-(1.0/(1.0*K)))*f[y][j];
} //cout<<f[0][1]<<endl;
printf("%.9lf",1.0*K*f[0][1]);
return 0;
}

[Codeforces-div.1 167B] Wizards and Huge Prize的更多相关文章

  1. Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp

    B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces 167B Wizards and Huge Prize(概率dp)

    题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...

  3. CodeForces 167B - Wizards and Huge Prize 期望概率dp

    初步分析:把赢了的巡回赛的a值加起来就是最后的剩余空间 这个明显的是状态转移的dp啊,然而他的状态比较骚是个数组,表示剩余空间,f(i,j,b),i表示比到第几场,j表示赢了几场,b就是里面的核心状态 ...

  4. [codeforces167B]Wizards and Huge Prize

    B. Wizards and Huge Prize time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  5. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  6. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  7. Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题

    D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...

  8. Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元

    E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...

  9. Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论

    C. Wizards and Numbers 题目连接: http://codeforces.com/problemset/problem/167/C Description In some coun ...

随机推荐

  1. bzoj 2733 平衡树启发式合并

    首先对于一个连通块中,询问我们可以直接用平衡树来求出排名,那么我们可以用并查集来维护各个块中的连通情况,对于合并两个平衡树,我们可以暴力的将size小的平衡树中的所有节点删掉,然后加入大的平衡树中,因 ...

  2. setTimeOut和闭包

    掘金上看到一个setTimeout与循环闭包的思考题.拿过来看了下,一方面了解settimeout的运行机制,还有就是js闭包的特性.关于闭包,有如下解释: 在这里写一点我对闭包的理解.理解闭包的关键 ...

  3. mave的依赖范围

    compile(编译范围) compile是默认的范围:如果没有提供一个范围,那该依赖的范围就是编译范 围.编译范围依赖在所有的classpath中可用,同时它们也会被打包. provided(已提供 ...

  4. Django【进阶】数据库查询性能相关

    之前项目中没有考虑过数据库查询关于效率的问题,如果请求量大,数据庞大,不考虑性能的话肯定不行.     tips:如图之前我们遇到过,当添加一张表时,作为原来表的外键,要给个默认值,现在我们写null ...

  5. 使用makecontext实现用户线程【转】

    转自:http://blog.csdn.net/cyberlabs/article/details/6920138 使用makecontext实现用户线程 现代Unix系统都在ucontext.h中提 ...

  6. Deep Learning基础--CNN的反向求导及练习

    前言: CNN作为DL中最成功的模型之一,有必要对其更进一步研究它.虽然在前面的博文Stacked CNN简单介绍中有大概介绍过CNN的使用,不过那是有个前提的:CNN中的参数必须已提前学习好.而本文 ...

  7. 2015多校第7场 HDU 5379 Mahjong tree 构造,DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5379 题意:一颗n个节点n-1条边的树,现在要给每个节点标号(1~n),要求:(1)每一层的兄弟节点的 ...

  8. python多进程处理数据

    当我们处理大规模数据如ImageNet的时候,单进程显得很吃力耗时,且不能充分利用多核CPU计算机的资源.因此需要使用多进程对数据进行并行处理,然后将结果合并即可.以下给出的是多进程处理的demo代码 ...

  9. 启动另一个activity

    1. 只负责启动 Intent intent = new Intent(mContext, BookOrderActivity.class); Bundle mEmployeeBundle = new ...

  10. mysql utf8改utf8mb4

    由于需要用到utf8mb4,之前是utf8现在给改成utf8mb4 查看当前环境 SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' ...