关于投资金额的一个计算问题,怎么使用C语言的程序编写的代码的方式实现的呢?

Problem Description
John never knew he had a grand-uncle, until he received the notary’s letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor.

John did not need that much money for the moment. But he realized that it would be a good idea to store this capital in a safe place, and have it grow until he decided to retire. The bank convinced him that a certain kind of bond was interesting for him.

This kind of bond has a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each year. The bond has no fixed term. Bonds are available in different sizes. The larger ones usually give a better interest. Soon John realized that the optimal set of bonds to buy was not trivial to figure out. Moreover, after a few years his capital would have grown, and the schedule had to be re-evaluated.

Assume the following bonds are available:
Value Annual interest
4000 400
3000 250

With a capital of 10 000 one could buy two bonds of 4 000, giving a yearly interest of 800. Buying two bonds of 3 000, and one of 4 000 is a better idea, as it gives a yearly interest of 900. After two years the capital has grown to 11 800 , and it makes sense to sell a 3 000 one and buy a 4 000 one, so the annual interest grows to 1 050. This is where this story grows unlikely: the bank does not charge for buying and selling bonds. Next year the total sum is 12 850, which allows for three times 4 000, giving a yearly interest of 1 200.

Here is your problem: given an amount to begin with, a number of years, and a set of bonds with their values and interests, find out how big the amount may grow in the given period, using the best schedule for buying and selling bonds.

Input
The first line contains a single positive integer N which is the number of test cases. The test cases follow.

The first line of a test case contains two positive integers: the amount to start with (at most 1 000 000), and the number of years the capital may grow (at most 40).

The following line contains a single number: the number d (1 <= d <= 10) of available bonds.

The next d lines each contain the description of a bond. The description of a bond consists of two positive integers: the value of the bond, and the yearly interest for that bond. The value of a bond is always a multiple of $1 000. The interest of a bond is never more than 10% of its value.

Output
For each test case, output – on a separate line – the capital at the end of the period, after an optimal schedule of buying and selling.

Sample Input
1
10000 4
2
4000 400
3000 250

Sample Output
14050

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

0
树状节点的编号的一个算法的问题,看下怎么使用C语言编写程序来计算
0
兔子和狼的应用问题的解答,计算兔子的位置的问题怎么使用C语言程序的设计解答
1
C语言设计简单计算问题
1
使用C语言进行一个月份的问题解决
0
最大最小极值的一个计算的问题,怎么采用C语言的程序的设计的思维来实现的
0
一个绘图填色的算法的计算问题,运用C语言的程序编写程序来实现的办法怎么做
0
计算房屋的价格的一个复习问题,怎么利用C语言的程序的设计来实现的呢
0
一个键盘的输入的问题的程序的计算,怎么利用C语言的程序的编写的过程实现的算法?
0
最短的等待时间的一个计算的问题,怎么采用C语言的程序的编写的实现?
0
图的步数的一个计算的问题,怎么利用C语言的程序的设计的思想去实现的?
0
日起的一个计算的问题,计算日期的编号采用C语言的程序的编写的技术?
0
计算可以抵达的最大的编号的问题,如何利用C语言的程序的编写的过程的技术实现
0
圆环的光路反射的一个算法的问题的计算,怎么采用C语言的程序的编写的思想实现?
0
拼写的计数的计算问题,运用C语言的程序的代码的编写的思路去实现的过程是怎么样的
0
犯罪金额和刑期的关系的计算问题,怎么利用C语言的代码程序语言编写的技术去实现呢?
1
计算开车经过的路程的问题,怎么使用C语言代码编写程序的思想去实现呢?
0
计算时间间隔的一个算法的求解问题,怎么利用C语言的程序代码编写的方式实现这个程序的计算的?
0
在圆上面计算点的问题,这个题目怎么采用C语言的代码编程序的思想去实现的程序?
0
数据结构实现任务的困难度计算,怎么使用C语言的程序代码设计的思路去编写程序的?
0
计算批量的容量矩阵的问题,怎么使用C语言的程序的设计的形式的思想去解决?