Clicker
2016-03-17 20:47
375 查看
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
Little Ho is obsessed with a computer game called “Clicker”. In this game player spends coins to raise his heroes’ level and gains more coins by sending his heroes to defeat monsters. At the beginning all Little Ho’s heroes are of level 0 and can do 0 damage to monsters. Raising ith hero from level 0 to level 1 costs Bi coins. Every time raising a hero to the next level costs 1.07 times(round down to the neareast integer) as much as previous time. So Raising ith hero from level X to level X+1 will cost [1.07…[1.07[1.07Bi]]…](repeat X times) coins where “[]” is the rounding function. Raising ith hero to one upper level can also raise his damage by Ai. So raising ith hero to level X will raise his damage to X*Ai.
Given the amount of coins Little Ho has, you are to calculate what is the maximum total damage can be reached by optimizing coin usage.
输入
Line 1: Two possitive integers N(1 <= N <= 30), M(1 <= M <= 20000). N is the number of heroes and M is the number of coins.
Line 2~N+1: Each line contains two possitive integers A(1 <= A <= 1000) and B(1 <= B <= 8000) representing a hero. A is the damage factor and B is the number of coins needed to raise his level from 0 to 1.
输出
Line 1: One integer, the maximum total damage.
样例提示
Hero 1 is raised to level 1, 10 damage, by 40 coins.
Hero 2 is raised to level 2, 50 damage, by 124(60+64) coins.
样例输入
2 170
10 40
25 60
样例输出
60
单点时限:1000ms
内存限制:256MB
描述
Little Ho is obsessed with a computer game called “Clicker”. In this game player spends coins to raise his heroes’ level and gains more coins by sending his heroes to defeat monsters. At the beginning all Little Ho’s heroes are of level 0 and can do 0 damage to monsters. Raising ith hero from level 0 to level 1 costs Bi coins. Every time raising a hero to the next level costs 1.07 times(round down to the neareast integer) as much as previous time. So Raising ith hero from level X to level X+1 will cost [1.07…[1.07[1.07Bi]]…](repeat X times) coins where “[]” is the rounding function. Raising ith hero to one upper level can also raise his damage by Ai. So raising ith hero to level X will raise his damage to X*Ai.
Given the amount of coins Little Ho has, you are to calculate what is the maximum total damage can be reached by optimizing coin usage.
输入
Line 1: Two possitive integers N(1 <= N <= 30), M(1 <= M <= 20000). N is the number of heroes and M is the number of coins.
Line 2~N+1: Each line contains two possitive integers A(1 <= A <= 1000) and B(1 <= B <= 8000) representing a hero. A is the damage factor and B is the number of coins needed to raise his level from 0 to 1.
输出
Line 1: One integer, the maximum total damage.
样例提示
Hero 1 is raised to level 1, 10 damage, by 40 coins.
Hero 2 is raised to level 2, 50 damage, by 124(60+64) coins.
样例输入
2 170
10 40
25 60
样例输出
60
#include "iostream" #include "fstream" #include "string.h" #include "math.h" using namespace std; #define max(a, b) a > b ? a : b; int N, M; int demage[35][150]; //demage[i][j]表示英雄i从等级1升级到等级j获得的杀伤力 int cost[35][150]; //cost[i][j]表示英雄i从等级1升级到等级j消耗的硬币 int f[35][20005]; //f[i][j]表示升级前i个英雄消耗j个硬币时获得的杀伤力 int main() { //ifstream cin; //cin.open("1.txt"); cin >> N; cin >> M; memset(f, 0, sizeof(f)); memset(cost, 0, sizeof(cost)); memset(demage, 0, sizeof(demage)); int ans = 0; int i, j; for(i=1; i<=N; i++) { cin >> demage[i][1] >> cost[i][1]; j = 1; int temp = floor(cost[i][1] * 1.07); while(1) { if(cost[i][j] > M) break; j++; cost[i][j] = cost[i][j-1] + temp; temp = floor(temp * 1.07); demage[i][j] = demage[i][j-1] + demage[i][1]; } for(j=1; j <=M; j++) //消耗的金币 { f[i][j] = max(f[i-1][j], f[i][j-1]); //未升级第i个英雄 for(int k=1; cost[i][k]<=j; k++) //升到哪一级 { f[i][j] = max(f[i][j], f[i-1][j-cost[i][k]] + demage[i][k]); } } } cout << f [M]; return 0; }
相关文章推荐
- 经典算法与数据结构的c++实现——shell排序算法
- 反向迭代器(rbegin,rend)
- Elasticsearch——Date Math在索引中的用法详解
- Paramiko,数据库
- 元编程
- drawRect 进阶
- DataBinding学习(四)
- Admob for Android不显示
- Python 错误和异常小结
- 使用JS或jQuery模拟鼠标点击a标签事件代码
- Android Studio 2.0 beta 7 发布
- apache poi 生成excel
- UVA1673 str2int(SAM)
- Red5源代码分析 - 关键类及其初始化过程
- JavaScript encodeURI() 函数
- 第一章:HTML基本语法
- ACM Program A
- Exynos4412 IIC总线驱动开发(一)—— IIC 基础概念及驱动架构分析
- Android 中关与类转换异常的问题。
- 赌博游戏如何吸引人