您的位置:首页 > 其它

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: