Codeforces 167B Wizards and Huge Prize(概率dp)
题意:
n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率
分析:
状态好确定,dp[i][j][k]表示前i个人击败j个背包容量是k是的概率,求概率正推,要注意这时背包容量能为负,我们把容量都加上B。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define B 201
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[][][*B+];
int a[],p[];
int n,l,k;
void solve(){
memset(dp,,sizeof(dp));
dp[][][B+k]=;
for(int i=;i<=n;++i)
for(int j=;j<=i;++j)
for(int k=;k<=*B;++k)
{
dp[i][j][k]+=dp[i-][j][k]*(-p[i]/100.0);//未击败第i个人
if(a[i]==-){
if(k>)//必须能放下一个财富
dp[i][j+][k-]+=dp[i-][j][k]*(p[i]/100.0);
}
else{
if(k+a[i]>*B)
dp[i][j+][*B]+=dp[i-][j][k]*(p[i]/100.0);
else
dp[i][j+][k+a[i]]+=dp[i-][j][k]*(p[i]/100.0);
}
}
//符合条件的情况的概率和
double total=0.0;
for(int j=l;j<=n;++j)
for(int k=B;k<=*B;++k)
total+=dp[n][j][k];
printf("%.12lf\n",total);
}
int main()
{
while(~scanf("%d%d%d",&n,&l,&k)){
for(int i=;i<=n;++i)
scanf("%d",&p[i]);
for(int i=;i<=n;++i)
scanf("%d",&a[i]); solve();
}
return ;
}
Codeforces 167B Wizards and Huge Prize(概率dp)的更多相关文章
- 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 ...
- CodeForces 167B - Wizards and Huge Prize 期望概率dp
初步分析:把赢了的巡回赛的a值加起来就是最后的剩余空间 这个明显的是状态转移的dp啊,然而他的状态比较骚是个数组,表示剩余空间,f(i,j,b),i表示比到第几场,j表示赢了几场,b就是里面的核心状态 ...
- [Codeforces-div.1 167B] Wizards and Huge Prize
[Codeforces-div.1 167B] Wizards and Huge Prize 试题分析 注意到每个物品互相独立,互不干扰之后就非常好做了. 算出一个物品最后的价值期望,然后乘以K即可. ...
- [codeforces167B]Wizards and Huge Prize
B. Wizards and Huge Prize time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Codeforces 678E. Another Sith Tournament(概率DP,状压)
Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
- Codeforces 601C Kleofáš and the n-thlon 概率dp
Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...
- Codeforces 280C Game on tree【概率DP】
Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...
随机推荐
- POJ2965The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 这个题的话,一开始也不会做,旁边的人说用BFS,后来去网上看了众大神的思路,瞬间觉得用BFS挺简单易:因为要让一个“+”变为“-”,只要将 ...
- MYSQL日常操作命令再熟悉
1,创建用户及密码: CREATE USER 'user'@'%' IDENTIFIED BY 'password'; 2,创建数据库: create database PDB_chengang de ...
- Android ActionBar与ViewPager合用
内容可以左右滑动,因为使用了ViewPager(我这里用了V4包) view_pager_main.xml <?xml version="1.0" encoding=&quo ...
- 通过快捷键及cmd命令注销系统
公司的外网内网是隔离的 外网的远程电脑屏幕一半卡那了,页面注销键正好在卡死的那一半屏幕上,用以下简单方法注销远程重新连接,问题解决了. 1.通过快捷键win+r打开“运行...” 2.输入CMD 回车 ...
- 【mysql的编程专题④】存储过程
类似函数,但是没有返回值,把sql进行封装,便于多次使用或多种应用程序共享使用.不能用在SQL语句中,只能使用CALL调用; 创建存储过程 语法 CREATE PROCEDURE sp_name ([ ...
- 测试Tomcat
- 250. Count Univalue Subtrees
题目: Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes ...
- 49. Anagrams
题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will ...
- Haxe数据类型
以下是Haxe里面的一些数据类型 基本类型 空特性 类 枚举 匿名结构 方法 动态 抽象 1. 基本类型Bool, Float, Int 2. 空特性由于Haxe可以被编译为各种不同的target,不 ...
- UNIX 高手的 20 个习惯[转]
使用 mkdir 的 -p 选项并在单个命令中创建所有父目录及其子目录要容易得多.但是即使对于知道此选项的管理员,他们在命令行上创建子目录时也仍然束缚于逐步创建每级子目录.花时间有意识地养成这个好习惯 ...