Bills
来源:互联网 发布:高一数学优化方案答案 编辑:程序博客网 时间:2024/06/06 03:54
There are N number kinds of bills with different worth. At this moment, you are allowed to use the same kinds of bills several times, but the total number of uses of all bills is restricted to less than K number.
Within this limitation, you want to know the maximum worth by making the worth one by one starting from 1 using the bills.
For example, N=2 is given, the worth of each bill is 1, 3 and K=5 is decided. Then you can make the worth up to 5 by using the bills whose worth is 1, and you can find it out from 6 to 13 as the below:
6 = 3+3
7 = 3+3+1
8 = 3+3+1+1
9 = 3+3+3
10 = 3+3+3+1
11 = 3+3+3+1+1
12 = 3+3+3+3
13 = 3+3+3+3+1
However, you cannot make 14 using 5 bills. Therefore, the maximum worth you can make is 13.
Time limit: 1 second (java: 2 seconds)
Input format
Several test cases can be included in the inputs. T, the number of cases is given in the first row of the inputs. After that, the test cases as many as T (T ≤ 30) are given in a row.
The maximum use number, K and the number of kinds of bills, N are given by being separated with a blank on the first row per each test case. (1 ≤ N ≤ 50, 1 ≤ K ≤ 200)
Each bill worth is given by being separated with a blank on the second row. Each worth is a natural number below 10,000.
Output format
Output the maximum worth you can when making worth using bills in order on the first row per each test case.
Example of Input
2
5 2
1 3
3 10
29 50 36 43 1 2 4 8 15 22
Example of Output
13
Within this limitation, you want to know the maximum worth by making the worth one by one starting from 1 using the bills.
For example, N=2 is given, the worth of each bill is 1, 3 and K=5 is decided. Then you can make the worth up to 5 by using the bills whose worth is 1, and you can find it out from 6 to 13 as the below:
6 = 3+3
7 = 3+3+1
8 = 3+3+1+1
9 = 3+3+3
10 = 3+3+3+1
11 = 3+3+3+1+1
12 = 3+3+3+3
13 = 3+3+3+3+1
However, you cannot make 14 using 5 bills. Therefore, the maximum worth you can make is 13.
Time limit: 1 second (java: 2 seconds)
Input format
Several test cases can be included in the inputs. T, the number of cases is given in the first row of the inputs. After that, the test cases as many as T (T ≤ 30) are given in a row.
The maximum use number, K and the number of kinds of bills, N are given by being separated with a blank on the first row per each test case. (1 ≤ N ≤ 50, 1 ≤ K ≤ 200)
Each bill worth is given by being separated with a blank on the second row. Each worth is a natural number below 10,000.
Output format
Output the maximum worth you can when making worth using bills in order on the first row per each test case.
Example of Input
2
5 2
1 3
3 10
29 50 36 43 1 2 4 8 15 22
Example of Output
13
56
C
#include <stdio.h>int a[64],b[2000005];int main(){ int i,j,k,t,n; scanf("%d",&t); while(t--) { scanf("%d%d",&k,&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=1; ;i++) { b[i]=1000; for(j=0;j<n;j++) if(i>=a[j]&&b[i]>b[i-a[j]]+1) b[i]=b[i-a[j]]+1; if(b[i]>k) break; } printf("%d\n",i-1); } return 0;}
0 0
- Bills
- Phone Bills
- Water Bills
- Phone Bills
- Phone Bills
- pat1016 Phone Bills
- 1016. Phone Bills (25)
- PAT_1016: Phone Bills
- 1016 Phone Bills (25)
- PAT 1016 Phone Bills
- PAT 1016. Phone Bills
- 1016. Phone Bills
- PAT1016. Phone Bills
- PAT1016. Phone Bills
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016.Phone Bills
- 队列 queue 的链表实现操作 -C++
- Vertica: 基于DBMS架构的列存储数据仓库
- Java并发--任务执行
- Linux服务器性能评估
- Swing添加鼠标右键菜单单击选择监听,并显示右键菜单
- Bills
- android,adb命令,查看,修改,文件权限
- C#调用百度翻译API实现自己的简单翻译工具
- 吐槽
- Alex 的 Hadoop 菜鸟教程: 第6课 Hbase 安装教程
- cocos2dx3.2 学习笔记(2)--ActionManagerTest(3)
- MakeFile基础知识(三)
- wx.python事件的绑定
- C++ Primer 【第四版】第十四章 重载操作符与转换