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,一经查实,立即删除!

相关文章

前端学习(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”模式…

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

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

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拆分、打包、压缩的使用方法。本文将在上篇文章的基础上进一步讲解在使…

【bzoj题解】1001 狼抓兔子

题目描述 现在小朋友们最喜欢"喜羊羊与灰太狼",话说灰太狼抓羊不到&#xff0c;但抓兔子还是比较在行的&#xff0c;而且现在的兔子还比较笨&#xff0c;它们只有两个窝&#xff0c;现在你做为狼王&#xff0c;面对下面这样一个网格的地形&#xff1a;左上角点为(1,1…

计算机网络宽带接入,计算机网络(宽带接入技术).ppt

计算机网络(宽带接入技术).ppt (26页)本资源提供全文预览&#xff0c;点击全文预览即可全文预览,如果喜欢文档就下载吧&#xff0c;查找使用更方便哦&#xff01;19.90 积分计算机网络 Computer Networks第六章 宽带接入技术宽带接入技术随着通信需求的发展&#xff0c;居民的通…

hapi返回xml格式 微信开发 node

圈内&#xff0c;使用Koa2、express比较多&#xff0c;而我hapi使用比较多。目前在做微信公众号开发&#xff0c;要求返回数据是xml格式。 1、之前的返回&#xff0c;直接return Json2Xml: async function (request, h) {const data <xml><ToUserName>< ![CD…

html css控制优先级,css权重及优先级问题_html/css_WEB-ITnose

css权重及优先级问题几个值的对比初始值指定值计算值应用值CSS属性的 指定值 (specified value)会通过下面3种途径取得&#xff1a; 在当前文档的样式表中给这个属性赋的值&#xff0c;会被优先使用。如果在当前文档的样式表中没有给这个属性赋值&#xff0c;那么它会尝试从父元…

Hbase集群监控

Hbase集群监控 Hbase Jmx监控 监控每个regionServer的总请求数&#xff0c;readRequestsCount&#xff0c;writeRequestCount&#xff0c;region分裂&#xff0c;region合并&#xff0c;Store 数据来源&#xff1a; /jmx?qryHadoop:serviceHBase,nameRegionServer,subServer 设…

学校计算机二级模拟上机能看分数吗,全国计算机二级考试机试考完怎么储存的...

全国计算机二级考试机试考完怎么储存的以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;全国计算机二级考试机试考完怎么储存的自动储存在系统里面&#xff0c;考试结束后上传&#xff0c;分数…

宝塔面板 创建 二级域名 Unable to round-trip http request to upstream

1、我的服务器是阿里云&#xff0c;安装了宝塔面板&#xff0c;直接使用宝塔面板创建二级域名bike.caowei.wang。 2、然后就想访问了&#xff0c;对不起&#xff0c;直接给你报错Unable to round-trip http request to upstream: dial tcp: lookup bike.caowei.wang: no suc…