hdu 1203 I NEED A OFFER!(01背包)
2015-06-03 16:16
561 查看
I NEED A OFFER!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19084 Accepted Submission(s): 7648
Problem Description
Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的。Speakless没有多少钱,总共只攒了n万美元。他将在m个学校中选择若干的(当然要在他的经济承受范围内)。每个学校都有不同的申请费用a(万美元),并且Speakless估计了他得到这个学校offer的可能性b。不同学校之间是否得到offer不会互相影响。“I NEED A OFFER”,他大叫一声。帮帮这个可怜的人吧,帮助他计算一下,他可以收到至少一份offer的最大概率。(如果Speakless选择了多个学校,得到任意一个学校的offer都可以)。
Input
输入有若干组数据,每组数据的第一行有两个正整数n,m(0<=n<=10000,0<=m<=10000)
后面的m行,每行都有两个数据ai(整型),bi(实型)分别表示第i个学校的申请费用和可能拿到offer的概率。
输入的最后有两个0。
Output
每组数据都对应一个输出,表示Speakless可能得到至少一份offer的最大概率。用百分数表示,精确到小数点后一位。
Sample Input
10 3 4 0.1 4 0.2 5 0.3 0 0
Sample Output
44.0% Hint You should use printf("%%") to print a '%'.
01背包模型求概率
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <string.h> #include <string> #include <vector> #include <queue> #define MEM(a,x) memset(a,x,sizeof a) #define eps 1e-8 #define MOD 10009 #define MAXN 10010 #define MAXM 100010 #define INF 99999999 #define ll __int64 #define bug cout<<"here"<<endl #define fread freopen("ceshi.txt","r",stdin) #define fwrite freopen("out.txt","w",stdout) using namespace std; int Read() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x; } void Print(int a) { if(a>9) Print(a/10); putchar(a%10+'0'); } double dp[10010]; int a[10010]; double p[10010]; int main() { // fread; int n,m; while(scanf("%d%d",&n,&m),(n+m)) { for(int i=1;i<=m;i++) { scanf("%d%lf",&a[i],&p[i]); p[i]=1.0-p[i]; } for(int i=0;i<=n;i++) dp[i]=1.0; // MEM(dp,1); // dp[0]=1.0; for(int i=1;i<=m;i++) { for(int j=n;j>=a[i];j--) { dp[j]=min(dp[j],dp[j-a[i]]*p[i]); } } dp =1-dp ; dp *=100; printf("%.1lf%%\n",dp ); } return 0; }
相关文章推荐
- JS实现窗口加载时模拟鼠标移动的方法
- 利用js实现禁止复制文本信息
- Js中自定义(创建)Map以及对应方法
- fedora 关闭防火墙的方法
- Devstack single node Installation on VM
- 开发者必须知道的HTML5十五大新特性
- 文件夹选择对话框 JS实现的两种方案
- CommonJS简介及模块标准
- 剑指offer之链表续
- ZH奶酪:JavaScript中的JSON.stringify() and JSON.parse()
- HTML5 新的 Input 类型
- HTML+CSS学习杂记——布局
- 剑指offer 39 - 二叉树的深度
- HTML学习笔记之二(回到顶部 与 回到底部)
- C#后台找不到前台html标签
- Jquery判断是不是移动设备浏览
- JS实现自适应宽度的Tag切换
- html学习笔记(1)——html基本格式
- Nodejs学习笔记(四)与MySQL交互(felixge/node-mysql)
- 前端一些词汇的缩写