I need A offer! POJ-1203

來源:互聯網
上載者:User

I NEED A OFFER!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11898    Accepted Submission(s): 4566


Problem DescriptionSpeakless很早就想出國,現在他已經考完了所有需要的考試,準備了所有要準備的材料,於是,便需要去申請學校了。要申請國外的任何大學,你都要交納一定的申請費用,這可是很驚人的。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 34 0.14 0.25 0.30 0
 


Sample Output

44.0%HintYou should use printf("%%") to print a '%'. 
 

#include <stdio.h>int m, n;int cost[10001];double e[10001], opt[10001], tmp;int main() {while (scanf("%d %d", &n, &m)) {if (m == 0 && n == 0)break;for (int i = 0; i < m; i++) {scanf("%d %lf", &cost[i], &e[i]);e[i] = 1.0 - e[i];}for (int i = 0; i <= n; i++)opt[i] = 1.0;for (int i = 0; i < m; i++) {for (int j = n; j >= cost[i]; j--) {tmp = opt[j - cost[i]] * e[i];if (opt[j] > tmp)opt[j] = tmp;}/*for (int i = 0; i <= n; i++)printf("%.2f ", opt[i]);puts("\n");*/}printf("%.1f%%\n", (1 - opt[n]) * 100);}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.