链接: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

HOJ 13828 Funfair相关推荐

  1. HOJ 1991 Happy 2005 HOJ 2635 Weights 快速幂

    http://acm.hit.edu.cn/hoj/problem/view?id=1991 HOJ 1991 Happy 2005 My Tags 矩阵快速幂   (Edit)   Source : ...

  2. HOJ 2576 HOJ 2577 Simple Computing I II 容斥原理

    两题的链接先给上: http://acm.hit.edu.cn/hoj/problem/view?id=2576 http://acm.hit.edu.cn/hoj/problem/view?id=2 ...

  3. HOJ 2278 IP Filtering (二分)

    HOJ 2278 主要思路:将IP地址看成4位256进制的数,转化成十进制,一个segment就是一个区间. 先将所有的segment按左端点升序排列,如果几个segment有重叠,则将它们合并成一个 ...

  4. HOJ——T 1867 经理的烦恼

    http://acm.hit.edu.cn/hoj/problem/view?id=1867 Source : HCPC 2005 Spring   Time limit : 2 sec   Memo ...

  5. hoj 1640 Mobile phones //poj 1195 Mobile phones 二维树状数组

    /* (x1,y2)   ____________    (x2,y2) |                      | |                      | |             ...

  6. HOJ 2786 Convert Kilometers to Miles

    http://acm.hit.edu.cn/hoj/problem/view?id=2786 公里转化为英里 公里数用最少个斐波那契数表示 即42表示为34+8 而不是34+5+2+1 #includ ...

  7. Hoj 1789 Electricity

    题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=1789 题目大意:在一个无向图中,删除某一个点所形成的最大连通分量数目是多少. 我们知道,删除一个点某个 ...

  8. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. HOJ P2143 Song(贪心)

    第二篇继续留给贪心 -------------------------------- HOJ P2143 Song Problem Description Time limit : 1 s   Mem ...

最新文章

  1. MyBatis 入门
  2. mysql sqlserver对比_很用心的写了 9 道 MySQL 面试题
  3. 通用四级联动下拉列表
  4. 2.1.3 计算机网络之编码与调制
  5. [INS-32025] 所选安装与指定 Oracle 主目录中已安装的软件冲突
  6. 关于hibernate的关联外键生成以及外键属性列的正确插入即:解决外键插入时,在关联表中除了外键列为空,其它属性均正常级联保存
  7. 《论语》读后颜渊第十二主要大意
  8. 华三实现vlan通过
  9. Python中将array类型不按科学计数法存在文件中的方法
  10. [Leedcode][JAVA][第11题][盛最多水的容器][双指针][贪心]
  11. can通道采样频率_哪个是嵌入式开发中最常用的外部总线:RS232?RS485?CAN?LIN?……...
  12. 科普:Windows下Netcat使用手册
  13. 关于缓存穿透,缓存击穿,缓存雪崩,热点数据失效问题的解决方案
  14. wordpress js 运行短代码_7个WordPress常用代码段(Code Snippets)
  15. 【数据结构:树】——搜索二叉树-K模型(非递归和递归)
  16. 信息安全技术——(十五)物联网关键技术
  17. Cocos 环境搭建 流程~~~~~
  18. 迭代算法8——近似迭代法之求定积分
  19. React中文文档之Hello world翻译
  20. 线路/信道编码技术(1)——8B/10B编码

热门文章

  1. C++基础知识(二)—— 变量和数据类型
  2. Python 爬虫利器三之 Xpath 语法与 lxml 库的用法
  3. 交叉编译和交叉调试环境搭建及使用
  4. React开发(273):异步调用的方式
  5. [Redux/Mobx] 在Redux中怎么发起网络请求?
  6. 数万字的0基础React知识大纲一定要藏藏好
  7. 前端学习(3048):vue+element今日头条管理-分页布局
  8. Vue手动封装实现一个五星评价得效果
  9. [html] HTML为什么要语义化?语义化有什么好处?
  10. [vue] 说说你对vue组件的设计原则的理解