HDU 最大報銷額 (0 1 背包)

最大報銷額

Time Limit : 1000/1000ms (Java/Other)???Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 29???Accepted Submission(s) : 11
Problem Description
現有一筆經費可以報銷一定額度的發票。允許報銷的發票類型包括買圖書(A類)、文具(B類)、差旅(C類),要求每張發票的總額不得超過1000元,每張發票上,單項物品的價值不得超過600元。現請你編寫程序,在給出的一堆發票中找出可以報銷的、不超過給定額度的最大報銷額。

?

Input
測試輸入包含若干測試用例。每個測試用例的第1行包含兩個正數 Q 和 N,其中 Q 是給定的報銷額度,N(<=30)是發票張數。隨后是 N 行輸入,每行的格式為: m Type_1:price_1 Type_2:price_2 ... Type_m:price_m 其中正整數 m 是這張發票上所開物品的件數,Type_i 和 price_i 是第 i 項物品的種類和價值。物品種類用一個大寫英文字母表示。當N為0時,全部輸入結束,相應的結果不要輸出。

?

Output
對每個測試用例輸出1行,即可以報銷的最大數額,精確到小數點后2位。

?

Sample Input
200.00 3
2 A:23.50 B:100.00
1 C:650.00
3 A:59.99 A:120.00 X:10.00
1200.00 2
2 B:600.00 A:400.00
1 C:200.50
1200.50 3
2 B:600.00 A:400.00
1 C:200.50
1 A:100.00
100.00 0

?

Sample Output
123.50
1000.00
1200.50

?

Source
浙大計算機研究生復試上機考試-2007年
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>using namespace std;double dp[40],money[40];int main(){//freopen("input.txt","r",stdin);double Q,a,b,c;int n;while(~scanf("%lf%d",&Q,&n) && n){memset(money,0,sizeof(money));int cnt=0,k;char ch;double num;for(int i=0;i<n;i++){scanf("%d",&k);int flag=1;a=b=c=0;for(int j=0;j<k;j++){getchar();scanf("%c:%lf",&ch,&num);if(num>600)flag=0;if(flag){if(ch=='A')a+=num;else if(ch=='B')b+=num;else if(ch=='C')c+=num;elseflag=0;}}if(flag && a<=600 && b<=600 && c<=600 && (a+b+c)<=1000){money[cnt++]=a+b+c;}}memset(dp,0,sizeof(dp));for(int i=0;i<cnt;i++)for(int j=cnt;j>=1;j--)if((dp[j-1]+money[i]<=Q))   //改成這樣可優化時間 if(j==1 || (dp[j-1]>0 && dp[j-1]+money[i]<=Q))dp[j]=max(dp[j],dp[j-1]+money[i]);double ans=0;for(int i=0;i<=cnt;i++)if(ans<dp[i])ans=dp[i];printf("%.2lf\n",ans);}return 0;
}

?

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388628.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388628.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388628.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

rstudio 關聯r_使用關聯規則提出建議(R編程)

rstudio 關聯r背景 (Background) Retailers typically have a wealth of customer transaction data which consists of the type of items purchased by a customer, their value and the date they were purchased. Unless the retailer has a loyalty rewards system, they …

PHP進程1608占用了9012,swoole (ERRNO 9012): worker exit timeout, forced to terminate

swoole server下使用了swoole_event_add&#xff0c;在關閉服務的時候日志中出現了提示swWorker_reactor_is_empty (ERRNO 9012): worker exit timeout, forced to terminate并且關閉服務時間比正常情況下要慢。解決方法開啟 reload_async > true 配置注冊onWorderExit回調&…

C#高級應用之CodeDomProvider引擎篇 .

using System; using System.Text; using System.CodeDom.Compiler; using System.Reflection; using Microsoft.CSharp; namespace ToolPackages.CodeDomProvider { public class SampleCodeDomProvider { //代碼生成器對象 private static System.CodeDom.Compiler.Code…

linux—命令匯總

pwd # 顯示當前工作目錄cd /tmp # cd切換工作目錄pwdcd ./dir01 # .當前工作目錄cd ../dir02 # ..上層工作目錄cd - # -前一個工作目錄cd ~ …

flex 添加右鍵鏈接

private var myMenu:ContextMenu;private function setViewerVersion():void{var menuItem:ContextMenuItem new ContextMenuItem("技術支持&#xff1a;中科天宇軟件有限公司", true, true);menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, functio…

jquery數據折疊_通過位折疊縮小大數據

jquery數據折疊Sometimes your dataset is just too large, and you need a way to shrink it down to a reasonable size. I am suffering through this right now as I work on different machine learning techniques for checkers. I could work for over 18 years and buy…

js基礎語法

||與&& a && b : 將a, b轉換為Boolean類型, 再執行邏輯與, true返回b, false返回aa || b : 將a, b轉換為Boolean類型, 再執行邏輯或, true返回a, false返回b轉換規則:對象為true非零數字為true非空字符串為true其他為false * 幾乎所有語言中||和&&都遵…

新鬼影病毒

今天和明天是最后兩天宿舍有空調的日子啦,暑假宿舍沒空調啊,悲催T__T 好吧,今天是最精華的部分啦對于鬼影3的分析,剩下的都是浮云啦,alg.exe不準備分析了,能用OD調試的貨.分析起來只是時間問題.但是MBR和之后的保護模式的代碼就不一樣啦同學們,純靜態分析,傷不起啊,各種硬編碼,…

php計算單雙,PHP中單雙號與變量

例子$string "beautiful";$time "winter";$str This is a $string $time morning!;echo $str. "";eval("\$str \"$str\";");echo $str;?>輸出&#xff1a;This is a $string $time morning!This is a beautiful win…

Silverlight:Downloader的使用(event篇)

(1)Downloader的使用首先我們看什么是Downloader,就是一個為描述Silverlight plug-in下載功能的集合.Downloader能異步的通過HTTP GET Request下載內容.他是一個能幫助Silverlight下載內容的一個對象,這些下載內容包括(XMAL content,JavaScript content,ZIP packages,Media,ima…

決策樹信息熵計算_決策樹熵|熵計算

決策樹信息熵計算A decision tree is a very important supervised learning technique. It is basically a classification problem. It is a tree-shaped diagram that is used to represent the course of action. It contains the nodes and leaf nodes. it uses these nod…

多虧了這篇文章,我的開發效率遠遠領先于我的同事

歡迎大家前往騰訊云社區&#xff0c;獲取更多騰訊海量技術實踐干貨哦~ 本文由獨木橋先生發表于云社區專欄 介紹 如果您有從Linux服務器上的源代碼安裝軟件的經驗&#xff0c;您可能會遇到make實用程序。該工具主要用于自動編譯和構建程序。它允許應用程序的作者輕松地布置構建該…

Free SQLSever 2008的書

Introducing SQL Server 2008 http://csna01.libredigital.com/?urss1q2we6這是一本提供自由使用書&#xff01;我把它翻譯&#xff0c;或轉送有什么關系&#xff01;這樣的書還是有幾本吧&#xff0c;Introducing Linq,Introducting Silverlight,都是啊&#xff01;嘿嘿。。。…

流式數據分析_流式大數據分析

流式數據分析The recent years have seen a considerable rise in connected devices such as IoT [1] devices, and streaming sensor data. At present there are billions of IoT devices connected to the internet. While you read this article, terabytes and petabytes…

oracle failover 區別,Oracle DG failover 實戰

Oracle dataguardfailover實戰操作步驟備庫&#xff1a;SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;SQL> SHUTDOWN IMMEDIATE;SQL> STARTUP;添加臨時文件&#xff0c;刪除老的臨時文…

Jenkins自動化CI CD流水線之8--流水線自動化發布Java項目

一、前提 插件&#xff1a;Maven Integration plugin 環境&#xff1a; maven、tomcat 用的博客系統代碼&#xff1a; git clone https://github.com/b3log/solo.git 遠端git服務器&#xff1a; [gitgit repos]$ mkdir -p solo [gitgit repos]$ cd solo/ [gitgit solo]$ git --…

oracle數據泵導入很慢,impdp導入效率的問題

內網從一臺服務器A導入到另一臺服務器B&#xff0c;38G的數據半個多小時才導了一個表。原來B庫上是有數據的&#xff0c;是不是因為TABLE_EXISTS_ACTIONREPLACE 導致速度慢了&#xff1f;parallel8也不知道會不會設高了。SQL> show parameter cpuNAME …

BZOJ2597 WC2007剪刀石頭布(費用流)

考慮使非剪刀石頭布情況盡量少。設第i個人贏了xi場&#xff0c;那么以i作為贏家的非剪刀石頭布情況就為xi(xi-1)/2種。那么使Σxi(xi-1)/2盡量小即可。 考慮網絡流。將比賽建成一排點&#xff0c;人建成一排點&#xff0c;每場未確定比賽向比賽雙方連邊&#xff0c;確定比賽向贏…

數據科學還是計算機科學_數據科學101

數據科學還是計算機科學什么是數據科學&#xff1f; (What is data science?) Well, if you have just woken up from a 10-year coma and have no idea what is data science, don’t worry, there’s still time. Many years ago, statisticians had some pretty good ideas…

開機流程與主引導分區(MBR)

由于操作系統會提供所有的硬件并且提供內核功能&#xff0c;因此我們的計算機就能夠認識硬盤內的文件系統&#xff0c;并且進一步讀取硬盤內的軟件文件與執行該軟件來完成各項軟件的執行目的 問題是你有沒有發現&#xff0c;既然操作系統也是軟件&#xff0c;那么我的計算機優勢…