链接: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. 2022年,我该用JAX吗?GitHub 1.6万星,这个年轻的工具并不完美
  2. 《转》Python学习(16)-python异常
  3. 并发编程之多线程基础-守护线程与非守护线程(四)
  4. pandas之Seris和DataFrame
  5. [jQuery基础] jQuery案例 -- qq音乐以及初步解决Ajax 跨域问题
  6. ios tabbar中间凸起_移动端开发基础【21】tabBar 配置
  7. 模型参考自适应控制器(MRAC)系列: 2.提升瞬态性能
  8. 计算机电路基础张志良,计算机电路基础 第2版
  9. 记录一个小程序 input输入框格式手机号方法
  10. 一个复杂注塑件抽取中面一般操作
  11. python读取文件详解_python 文件读取方法详解
  12. php 闭合标记,什么叫自闭合标签?自闭标签有什么用
  13. Java自动识别身份证信息
  14. foreach变异非变异_神经网络产生了一堆看起来很变异的新动物
  15. 谷歌真被ChatGPT搞慌了!两位创始人紧急回归制定战术,搜索广告根基不容有失...
  16. 【代码复用之】登录注册原生代码
  17. LeetCode——第121题:买股票的最佳时机
  18. ant linux tools.jar,为什么ant在错误的目录中寻找tools.jar?
  19. Ray 分布式简单教程(1)
  20. 探索艾利特机器人|EC612在汽车零部件行业上下料的应用

热门文章

  1. Linux C 函数练习
  2. linux内存映射函数mmap
  3. yarn安装依赖包报错 error An unexpected error occurred: “https://registry.npm.taobao.orgnpm/element-ui: get
  4. React开发(209):react错误边界
  5. Taro+react开发(57) 图片引入
  6. 前端学习(2759):button按钮使用
  7. “约见”面试官系列之常见面试题之第七十五篇之vue中如何使当前css起作用(建议收藏)
  8. 前端学习(1749):前端调试值之如何查看整站的资源和编辑
  9. oracle之单行函数之子查询
  10. Oracle从小白到大牛的刷题之路(建议收藏学习)