`
phinecos
  • 浏览: 342663 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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

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

#include<iostream>
#include
<cstdio>
usingnamespacestd;

doublesum,a[40],b,bb;
intn,nn,m;
charss[110];

doubledfs(intcur,doublev)
{
if(cur>=n)returnv;
doubleret=0,ret2=dfs(cur+1,v);
if(v+a[cur]<=sum+1e-8)ret=dfs(cur+1,v+a[cur]);
returnret>ret2?ret:ret2;
}


intmain()
{
cout.precision(
2);cout.setf(ios::fixed);
while(cin>>sum>>nn&&nn){
for(n=0;nn--;n+=a[n]<=1000+1e-8&&bb<=600+1e-8){
for(cin>>m,a[n]=bb=0;m--;){
cin
>>ss;
sscanf(ss
+2,"%lf",&b);
bb
=bb>b?bb:b;
a[n]
+=(ss[0]>='A'&&ss[0]<='C'?b:1001);
}

}

cout
<<dfs(0,0)<<endl;
}

return0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics