I NEED A OFFER!

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 ‘%’.

思路:根据题目中的要求求出获得offer的最大可能。

一维数组,两层循环。第一层代表现在所选择的学校,第二层代表所拥有的资本。
memset函数只能对数组进行0或者-1的赋值。
熟悉动态规划的整个过程。题中求或者offer的最大可能,我们可以求拿不到offer的最小的可能。

代码如下:

#include<iostream>
#include<cmath>
#include<set>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<string>
using namespace std;
int a,b,c,d,f,g,sum,r[10010];//r用来存去某所学校所需的金额
double r1[10010],dp[10010];//r1用来存每个学校获得offer的可能,dp用来存得不到offer的最小的可能
int main(){
    while(scanf("%d%d",&a,&b)!=EOF&&(a||b)){
        memset(r,0,sizeof(r));
        memset(r1,0,sizeof(r1));
        for(int i=0;i<=a;i++){
            dp[i]=1.0;//对dp中的所有数据初始化为1.0
        }
        for(int i=1;i<=b;i++){
            scanf("%d%lf",&r[i],&r1[i]);
        }
        for(int i=1;i<=b;i++){
            for(int j=a;j>=r[i];j--){
                dp[j]=min(dp[j],dp[j-r[i]]*(1.0-r1[i]));//得到拿不到offer的最小的可能
            }
        }
        printf("%.1lf%%\n",(1-dp[a])*100);//注意输出格式的问题
    }
    return 0;
}
Dear Friend ; Especially for you - this amazing announcement . This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 2316 , Title 1 ; Section 303 ! This is not a get rich scheme . Why work for somebody else when you can become rich in 77 months . Have you ever noticed society seems to be moving faster and faster and more people than ever are surfing the web ! Well, now is your chance to capitalize on this ! We will help you turn your business into an E-BUSINESS and sell more . You can begin at absolutely no cost to you . But don't believe us . Ms Ames who resides in Indiana tried us and says "Now I'm rich, Rich, RICH" . We are licensed to operate in all states . If not for you then for your LOVED ONES - act now ! Sign up a friend and you'll get a discount of 30% ! Thank-you for your serious consideration of our offer . Dear Colleague ; Your email address has been submitted to us indicating your interest in our letter ! This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 2516 ; Title 1 , Section 304 . This is not a get rich scheme ! Why work for somebody else when you can become rich inside 34 months ! Have you ever noticed how long the line-ups are at bank machines plus people will do almost anything to avoid mailing their bills ! Well, now is your chance to capitalize on this ! We will help you process your orders within seconds and deliver goods right to the customer's doorstep ! You are guaranteed to succeed because we take all the risk ! But don't believe us . Mr Simpson of Oregon tried us and says "I've been poor and I've been rich - rich is better" . We are licensed to operate in all states . We urge you to contact us today for your own future financial well-being . Sign up a friend and you get half off . Thank-you for your serious consideration of our offer . Dear Salaryman ; Your email address has been submitted to us indicating your interest in our briefing . This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 1625 , Title 8 , Section 301 ! This is different than anything else you've seen ! Why work for somebody else when you can become rich in 38 weeks . Have you ever noticed how many people you know are on the Internet and nearly every commercial on television has a .com on in it ! Well, now is your chance to capitalize on this ! WE will help YOU deliver goods right to the customer's doorstep plus increase customer response by 160% ! You can begin at absolutely no cost to you . But don't believe us ! Prof Simpson who resides in Idaho tried us and says "I was skeptical but it worked for me" ! We are licensed to operate in all states ! We IMPLORE you - act now . Sign up a friend and you'll get a discount of 30% . Thanks . 找出flag
最新发布
05-12
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺旺的碎冰冰~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值