Sicily1221:数字游戏(week 10)

本文介绍了一款数字游戏,玩家需在限定回合内选择并擦除数字,使总分最大化。通过动态规划算法实现了最优解的计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接: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[n][m] << endl;  

    cin >> n;  

    return 0;  
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值