您的位置:首页 > 其它

Sicily1221:数字游戏(week 10)

2017-05-07 20:31 676 查看
题目链接:http://soj.sysu.edu.cn/1221

1221. 数字游戏

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

小W发明了一个游戏,他在黑板上写出了一行数字a1,a2,….an,然后给你m个回合的机会,每回合你可以从中选择一个数擦去它,接着剩下来的每个数字ai都要递减一个值bi。如此重复m个回合,所有你擦去的数字之和就是你所得到的分数。

小W和他的好朋友小Y玩了这个游戏,可是他发现,对于每个给出的an和bn序列,小Y的得分总是比他高,所以他就很不服气。于是他想让你帮他算算,对于每个an和bn序列,可以得到的最大得分是多少。这样他就知道有没有可能超过小Y的得分。

Input

第一行,一个整数n(1<=n<=200),表示数字的个数。

第二行,一个整数m(1<=m<=n),表示回合数。

接下来一行有n个不超过10000的正整数,a1,a2…an,表示原始数字

最后一行有n个不超过500的正整数,b1,b2….bn,表示每回合每个数字递减的值

Output

一个整数,表示最大可能的得分

Sample Input

3 310 20 304 5 6

Sample Output

47

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string.h>
using namespace std;

struct thing {
int a, b;
};

thing t[205];
int dp[205][205];

bool cmp(const thing & t1, const thing & t2) {
return t1.b > t2.b;
}

int main() {

//std::ios::sync_with_stdio(false);

int n, m;
cin >> n >> m;

for (int i = 0; i < n; i++) cin >> t[i].a;
for (int i = 0; i < n; i++) cin >> t[i].b;
sort(t, t + n, cmp);

for (int j = 0; j <= m; j++) dp[0][j] = 0;
for (int i = 0; i <= n; i++) dp[i][0] = 0;

for (int i = 0; i < n; i++) {
for (int j = 1; j <= m; j++) {
dp[i + 1][j] = max(dp[i][j], dp[i][j - 1] + t[i].a - t[i].b * (j - 1));
}
}

cout << dp
[m] << endl;

cin >> n;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sicily