2007浙大复试上机考试题目6--最大报销额

--------------------------------------------------------------------------------

题目要求:

现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。

具体的输入输出格式规定如下:

输入格式:测试输入包含若干测试用例。每个测试用例的第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 项物品的种类和价值。物品种类用一个大写英文字母表示。当N0时,全部输入结束,相应的结果不要输出。

输出格式:对每个测试用例输出1行,即可以报销的最大数额,精确到小数点后2位。

输入样例:

200.00 3

<chmetcnv w:st="on" unitname="a" sourcevalue="2" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">2 A</span></chmetcnv>:23.50 B:100.00

<chmetcnv w:st="on" unitname="C" sourcevalue="1" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1 C</span></chmetcnv>:650.00

<chmetcnv w:st="on" unitname="a" sourcevalue="3" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">3 A</span></chmetcnv>:<chmetcnv w:st="on" unitname="a" sourcevalue="59.99" hasspace="True" negative="False" numbertype="1" tcsc="0">59.99 A</chmetcnv>:120.00 X:10.00

1200.00 2

2 B:<chmetcnv w:st="on" unitname="a" sourcevalue="600" hasspace="True" negative="False" numbertype="1" tcsc="0">600.00 A</chmetcnv>:400.00

<chmetcnv w:st="on" unitname="C" sourcevalue="1" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1 C</span></chmetcnv>:200.50

1200.50 3

2 B:<chmetcnv w:st="on" unitname="a" sourcevalue="600" hasspace="True" negative="False" numbertype="1" tcsc="0">600.00 A</chmetcnv>:400.00

<chmetcnv w:st="on" unitname="C" sourcevalue="1" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1 C</span></chmetcnv>:200.50

<chmetcnv w:st="on" unitname="a" sourcevalue="1" hasspace="True" negative="False" numbertype="1" tcsc="0"><span style="font-size: 10pt; font-family: Verdana;" lang="EN-US">1 A</span></chmetcnv>:100.00

100.00 0

输出样例:

123.50

1000.00

1200.50

-------------------------------------------------------------------------

None.gif #include < iostream >
None.gif#include
< cstdio >
None.gif
using namespace std;
None.gif
None.gif
double sum,a[ 40 ],b,bb;
None.gif
int n,nn,m;
None.gif
char ss[ 110 ];
None.gif
None.gif
double dfs( int cur, double v)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
if(cur>=n)returnv;
InBlock.gif
doubleret=0,ret2=dfs(cur+1,v);
InBlock.gif
if(v+a[cur]<=sum+1e-8)ret=dfs(cur+1,v+a[cur]);
InBlock.gif
returnret>ret2?ret:ret2;
ExpandedBlockEnd.gif}

None.gif
None.gif
int main()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifcout.precision(
2);cout.setf(ios::fixed);
ExpandedSubBlockStart.gifContractedSubBlock.gif
while(cin>>sum>>nn&&nn)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(n=0;nn--;n+=a[n]<=1000+1e-8&&bb<=600+1e-8)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(cin>>m,a[n]=bb=0;m--;)dot.gif{
InBlock.gifcin
>>ss;
InBlock.gifsscanf(ss
+2,"%lf",&b);
InBlock.gifbb
=bb>b?bb:b;
InBlock.gifa[n]
+=(ss[0]>='A'&&ss[0]<='C'?b:1001);
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gifcout
<<dfs(0,0)<<endl;
ExpandedSubBlockEnd.gif}

InBlock.gif
return0;
ExpandedBlockEnd.gif}

None.gif
None.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值