[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. 大聊Python-----网络编程

    什么是Socket? socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递. 我们知道网络 通信 都 是基于 ip+port 方能定位到目标的具体机器 ...

  2. javascript中=、==与===的区别

    1.等号 =赋值运算符,给变量赋值 var a="1"; 2.相等和不相等操作符 相等操作符由==表示,若两个操作数相等,则返回true:不相等操作符由!=表示,若两个操作数不相等 ...

  3. bootstrap-table组合表头

    1.效果图 2.html代码 <table id="table"></table> 3.javascript代码 $("#table") ...

  4. perl登录ssh

    use warnings; use strict; use Net::SSH::Perl; my $host = '192.168.255.128'; my $username = 'root'; m ...

  5. [Leetcode Week15] Add Two Numbers

    Add Two Numbers 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/add-two-numbers/description/ Descrip ...

  6. MVC自定义路由实现URL重写,SEO优化

    //App_Start-RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollect ...

  7. 解决sql server中批处理过程中“'CREATE/ALTER PROCEDURE 必须是查询批次中的第一个语句”

    在批处理中加字段或表或视图或存储过程是否存在的判断 -----------------------------------------line----------------------------- ...

  8. C后端设计开发 - 第4章-武技-常见轮子下三路

    正文 第4章-武技-常见轮子下三路 后记 如果有错误, 欢迎指正. 有好的补充, 和疑问欢迎交流, 一块提高. 在此谢谢大家了. Moonlight Shadow   纪念那个我爱的, 被我感动的女孩 ...

  9. 给mongodb设置密码权限

    昨天装了个mongodb数据库用于测试用,装好后没有密码,现在就讲讲怎么设置密码 1.首先进入C:\mongodb\bin下面运行mongod.exe启动数据库. 2.在相同目录下启动mongo.ex ...

  10. Leetcode 之Binary Tree Postorder Traversal(47)

    中序遍历二叉搜索树,得到的是一个有序的结果,找出其中逆序的地方就可以了.如果逆序的地方相邻,只需把逆序的相换即可:如果不相邻,则需要找到第二个逆序对的 第二个元素再做交换. 定义两个指针p和q来指定需 ...