hdu1203 I NEED A OFFER!
来源:互联网 发布:大数据用到的java 编辑:程序博客网 时间:2024/06/05 21:16
刚看到题,思路不是很清晰,不过考虑了一会就想到了0-1背包问题了。
拿到的OFFER 1 - m 份。
在资金允许的范围内求至少拿到一份OFFER的概率,也就是求拿不到OFFER的概率f[j].
f[j] = min ( f[ j - a[i] ] * ( 1 - b[i] ], f[j] ).
ans = 1 - f[j];
#include <stdio.h>const int MAXN = 10005;struct Good { int cost; double p;}good[MAXN];double min ( double a, double b ) { return a < b ? a : b;}int main ( ) { int m, n; double f[MAXN]; while ( scanf ( "%d%d", &n, &m ) != EOF ) { if ( n == 0 && m == 0 ) break; for ( int i = 0; i < m; ++i ) scanf ( "%d %lf", &good[i].cost, &good[i].p ); for ( int i = 0; i <= n; ++i ) f[i] = 1; double res = 1; for ( int i = 0; i < m; ++i ) for ( int j = n; j >= good[i].cost; --j ) { f[j] = min ( f[j - good[i].cost] * ( 1 - good[i].p ), f[j] ); res = min ( res, f[j] ); } printf ( "%.1lf%%\n", ( 1 - res ) * 100 ); }}
- I need a offer!(hdu1203)
- hdu1203 I NEED A OFFER!
- hdu1203 I NEED A OFFER!
- HDU1203 I NEED A OFFER!
- hdu1203 I NEED A OFFER!
- HDU1203-I NEED A OFFER!
- HDU1203,I NEED A OFFER!
- HDU1203 I NEED A OFFER!
- hdu1203(I NEED A OFFER!)
- I NEED A OFFER! hdu1203
- hdu1203 I NEED A OFFER!
- HDU1203-I NEED A OFFER!
- HDU1203 I NEED A OFFER!
- 【HDU1203】I NEED A OFFER!
- #HDU1203 I NEED A OFFER!
- hdu1203--I NEED A OFFER!
- HDU1203--I NEED A OFFER!--0-1
- hdu1203 I NEED A OFFER! (01背包)
- 一种 树节点宽度优先遍历算法
- 如何检验光盘镜像(ISO格式文件)并刻录系统安装光盘?
- C#多线程:异步事件调用
- MySQL架构
- Set Cluster Interconnects in Oracle RAC
- hdu1203 I NEED A OFFER!
- IOS HTTP Living Strem详解一
- C++实现享元模式
- VC++2012编程演练数据结构《33》希尔排序
- 进程间通信之信号量--使用信号实现生产者消费者问题
- 最长上升子序列
- IOS HTTP Living Strem详解二
- ios Http living Stream详解三
- gridView显示图片以及对应的文字