哈理工OJ 2274 Heroic Action(01坑背包)
題目鏈接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2274
Heroic Action
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 35(11 users) Total Accepted: 12(11 users) Rating: Special Judge: No
Description
The hero has infiltrated the villain’s island and beat the villain again! But the villain still
refused to lose and activated the island’s self-destruction system. The island will soon
explode. Luckily, the hero has managed to find a parachute and jumped from the tall tower
on the island with a height of y meters. Now he hopes to get away from the island as far
as possible. While in the air, the hero can do n kinds of actions, while doing the i-th
action, his height will decrease a i meters and he will move forward b i meters. If the
current height of the hero is smaller than the height the action required, then the hero
cannot perform this action. If the hero does nothing, he will fall straight down slowly.
Remember, the same kind of action can be only performed once. And the hero can choose
to perform whatever actions in any order he wish.
Now give you the tower’s height y, and all the actions the hero can perform, please
calculate the maximum horizontal distance from the island the hero can get.
Input
The first line is the number of test cases T.
For each test cases, the first line contains two integers, y(1 ≤ y ≤ 1000) and n(1 ≤
n ≤ 1000). Then n lines follows, each line has two integers ai (1 ≤ ai ≤ y) and bi (1 ≤ bi ≤
105 ), representing the height the hero will lose and the distance he will gain after
performing this action.
Output
For each test cases, output a single line containing the maximum distance from the island the hero can get.
Sample Input
2
10 2
10 10
10 5
20 5
5 1
5 1
5 1
5 1
5 1
Sample Output
10
4
【思路分析】其實就是簡單的背包,坑點在于用max函數(shù)會超時,無論是自己寫還是調(diào)用函數(shù)庫里的嗎,用if來判斷就不會超時,是不是有點坑。
【AC代碼】
總結(jié)
以上是生活随笔為你收集整理的哈理工OJ 2274 Heroic Action(01坑背包)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 速读训练软件_记忆宫殿记忆力训练教程-第
- 下一篇: 配置CNPM-基础案例