HOJ 13828 Funfair

链接:http://acm.hnu.cn/online/?action=problem&type=show&id=13828

Problem description
We are going to a funfair where there are n games G1,...,Gn. We want to play k games out of the n games, and we can choose the order in which we play them—note that we cannot play any game more than once. We have to specify these k games and their order before starting any game.
At each point in time, we have some amount of money, which we use in playing the games. At the beginning, we have x0 Oshloobs of money. If before playing game Gi, we have x Oshloobs and we win in Gi, our money increases to x+Ai for some Ai ⩾ 0. If we have x Oshloobs before playing game Gi and we lose in Gi, we lose Li percent of x. The probability that we win game Gi (independently of other games) is Pi percents.
The goal is to play k of the games in such an order to maximize the expected amount of money we end up with after playing all k selected games in that order.

Input
There are multiple test cases in the input. The first line of each test case contains three space-separated integers n, k, and x0 (1 ⩽ k ⩽ n ⩽ 100, 0 ⩽ x0 ⩽ 106). Each of the next n lines specifies the properties of game Gi with three space-separated integers Ai, Li, and Pi (0 ⩽ Ai,Li,Pi ⩽ 100). The input terminates with a line containing 0 0 0 which should not be processed.

Output
For each test case, output a single line containing the maximum expected amount of our final money rounded to exactly two digits after the decimal point.

Sample Input
2 2 100
10 0 50
100 10 20
2 1 100
10 0 50
100 10 20
0 0 0
Sample Output
117.00
112.00

思路:dp;

场上想到了dp,但是排序处理的不好所以一直没有A掉;现在改了一下…………

赢: (Ai + x) * Pi
输: (1 - Pi)(1 - Li) * x
那我过完这一关剩余钱的期望是(1 - Li + LiPi) * x + Ai * Pi
假设 c = (1 - Li + LiPi)d = Ai * Pi
即: cx + d
那么,在考虑先过A关还是B关的时候,有两种可能性,
先过A关:c2 * (c1*x+d1) + d2;
先过B关:c1 * (c2*x+d2) + d1;
假设A大于B,c2 * (c1*x+d1) + d2 > c1 * (c2*x+d2) + d1
所以只需按此关系排序即可;然后开始dp;
转移方程:

if(j==i) dp[i][j]=c*dp[i-1][j-1]+d;
else
{
dp[i][j]=max(dp[i-1][j],c*dp[i-1][j-1]+d);
}

具体详见代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=105;
struct node
{double a,l,p,c,d;node(double _a=0.0,double _l=0.0,double _p=0.0):a(_a),l(_l),p(_p){c=1-l+l*p;d=a*p;}bool operator <(const node &r)const{return d*r.c+r.d>r.d*c+d;}
};
node ga[maxn];
double dp[maxn][maxn];int main()
{freopen("input.txt","r",stdin);int n,k;double x0;while(scanf("%d%d%lf",&n,&k,&x0),n){int nw=0,nl=0;for(int i=1;i<=n;i++){double ta,tl,tp;scanf("%lf%lf%lf",&ta,&tl,&tp);ga[i]=node(ta,tl/100.0,tp/100.0);}memset(dp,0,sizeof dp);sort(ga+1,ga+1+n);for(int i=0;i<=n;i++)dp[i][0]=x0;for(int i=1;i<=n;i++){int s=min(k,i);double c=ga[i].c,d=ga[i].d;for(int j=1;j<=s;j++){if(j==i)    dp[i][j]=c*dp[i-1][j-1]+d;else{dp[i][j]=max(dp[i-1][j],c*dp[i-1][j-1]+d);}}}printf("%.2lf\n",dp[n][k]);}return 0;
}

 

 

转载于:https://www.cnblogs.com/MeowMeowMeow/p/7299208.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416227.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Z-Blog 爬虫 node实现

Z-Blog 爬虫 node实现 目前正在连载更新中 一、需求 帮朋友建站&#xff0c;指定用Z-Blog&#xff0c;安装后&#xff0c;我发现采集文章不便&#xff0c;所以准备写一个node爬虫&#xff0c;实现对友站文章的自动采集。 二、实现之前的思考 1、 熟悉Z-Blog数据库 Z-Blog使…

前端学习(2512):组件注册

app.vue <template><div id"app"><users></users></div> </template><script> import Users from ./components/User export default {name: App,data () {return {title: 这是我的第一个标题}},components: {users: Use…

中考物理可不可以用计算机,不能用计算机?2021年起广州中考课目改为“4+4”...

昨日&#xff0c;广州市教育局发布公告&#xff0c;明确提出广州将从2021年开始实施高中阶段学校考试招生制度改革(与在读初一学生相关)&#xff0c;改革实施前的2019至2020年为过渡期(与在读初二、初三学生相关)。从2021年开始&#xff0c;广州中考录取计分科目采用“44”模式…

superagent返回结果乱码

使用superagent返回结果乱码&#xff0c;处理编码的时候主要就分为utf-8以及gbk两大类&#xff0c;需要使用superagent-charset工具包解决问题 const charset require(superagent-charset); const superagent charset(require(superagent));const result await superagent.…

科学计算机java算法实现,(Java)科学型计算器开发及实现.doc

(Java)科学型计算器开发及实现淮北师范大学科学型计算器的开发与实现学 院 计算机科学与技术 专 业学 生 姓 名学 号指导教师姓名科学型计算器的开发与实现作 者&#xff1a;指导教师&#xff1a;摘 要&#xff1a;目前&#xff0c;科学计算器的应用非常广泛&#xff0c;从科研…

node process.env.NODE_ENV 使用 cross-env 配置 设置

process是一个全局对象&#xff0c;任意位置可以访问。在开发测试和正式部署时&#xff0c;需要区分不同的环境process.env.NODE_ENV&#xff0c;包括development和production&#xff0c;我推荐使用工具包cross-env实现在命令行中设置&#xff0c;解决跨平台问题。 1、全局安…

BI@Report烂笔头

有的时候&#xff0c;一定要设置浮动表元&#xff01;&#xff01;1. 一个红框就是一个报表2. 浮动表元 代表着按这个字段来group by&#xff08;但是数据库不能这么来&#xff09;3. _n求这个指标维的个数 sum(b2$)求和4. 小手抓数据 / 数据源中拖过去5. 当选择排序类型&#…

微型计算机相关的英文文献,微型计算机控制系统--------外文文献翻译

内容介绍Electronic systems are used for handing information in the most general sense; this information may be telephone conversation, instrument read or a company’s accounts, but in each case the same main type of operation are involved: the processing, …

Z-Blog 扩展数据库 字段 二次开发

需求 因为自己写了采集器往Z-Blog数据库中增加数据&#xff0c;友站的文章需要列出出处&#xff0c;尊重版权&#xff0c;所以需要对数据库字段进行扩展&#xff0c;增加采集站点名称和采集详情页链接字段&#xff0c;并且在Z-Blog系统文章页显示出来。 1、在数据库对应的zbp…

以计算机谈人文科学,阅读下面一段文字,完成问题   自20世纪80年代以来,世界都在谈“软科学技术”,何谓软科学?经常听人说:“脑子不够使。”这其实就是对软科学的需求。于是,从古至今,...

阅读下面一段文字&#xff0c;完成问题自20世纪80年代以来&#xff0c;世界都在谈“软科学技术”&#xff0c;何谓软科学&#xff1f;经常听人说&#xff1a;“脑子不够使。”这其实就是对软科学的需求。于是&#xff0c;从古至今&#xff0c;所谓“军师”、“谋士”、“智囊团…

ssh报错解决 ECDSA host key for 123.56.11.181 has changed and you have requested strict checking.

起因&#xff1a;云服务器重装了系统&#xff0c;导致本地的SSH信息便失效了&#xff0c;所以会报错。 解决办法: ssh-keygen -R 123.56.11.181 目的是清除本地关于远程服务器的缓存和公钥信息。

前端学习(2516):传值和引用

传引用 数据都会变化 传值 不变化

计算机专业英语教程计算机硬件翻译,计算机专业英语教程第5版翻译

storage over a channel (such as a coaxial cable). The message is interpreted, and the processor initiates action to retrieve the appropriate program and data from secondary storage [3].The program and data are “loaded”, or moves, to primary storage from …

hibernate状态转换关系图【原】

hibernate状态转换 其它参考 简单理解Hibernate三种状态的概念及互相转化 简单的Hibernate入门介绍转载于:https://www.cnblogs.com/whatlonelytear/p/7326353.html

宝塔 面板 放行端口

今天尝试了宝塔面板配置环境&#xff0c;发现我在8080端口启动了服务&#xff0c;从外网访问&#xff0c;并不能访问&#xff0c;后来发现需要在宝塔面板的安全功能下设置放行端口既可以解决问题。 1、开启一个服务 http-server . -a 0.0.0.0 -p 8080 2、在宝塔面板中设置 …

html打包成app的缓存问题,webpack 独立打包与缓存处理

关于微信公众号&#xff1a;前端呼啦圈(Love-FED)个人博客&#xff1a;劳卜的博客知乎专栏&#xff1a;前端呼啦圈前言先前写了一篇webpack入门的文章《webpack入门必知必会》&#xff0c;简单介绍了webpack拆分、打包、压缩的使用方法。本文将在上篇文章的基础上进一步讲解在使…