上海金马五校DHU(Ball Game)

本文介绍了一种通过放置不同类型的球来获得最大总分数的游戏算法。利用四维动态规划方法,详细阐述了如何计算每一步操作的最佳得分策略,旨在帮助玩家理解如何最大化得分。

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

Problem B : Ball Game


Submit 

Time Limit: 3 s

Description

There are 4 types of balls (ABC and D) and a huge box. The balls of the same type have the same weight.

Lily likes to play a game. She puts theses balls into the box one by one. Suppose she has already put some balls into the box and their total weight is w. When she continues putting a new ball into the box, she will receive a bonus score, denoted as c. The value of c equals to the product of the weight of the new ball and the last digit of w. Note that when the box is empty, the value of w is 0.

Now give you the number of each type of balls and their weights, can you tell Lily the maximum score she can get in total?

Input

There are several test cases. Each test case has one line containing 8 numbers.

Each of the first 4 numbers, ABC and D (0 ≤ ABCD ≤ 30), indicates the number of the respective type of balls.

Each of the next 4 numbers, abc and d (1 ≤ abcd ≤ 100,000), indicates the weight of the respective type of balls.

Output

For each test case, print one line with the maximum total score Lily can get.

Sample Input

1 1 1 1 2 3 4 5
3 6 8 8 25 66 18 12

 

Sample Output

 

71
5213

 


Author: Alez

四维dp。。。

#include <bits/stdc++.h>
#define LL long long
using namespace std;
int dp[50][50][50][50];
int wA,wB,wC,wD;
int fun(int a,int b,int c,int d)
{
    return a*wA+b*wB+c*wC+d*wD;
}
int main()
{
    int cntA,cntB,cntC,cntD;
 
    while(cin>>cntA>>cntB>>cntC>>cntD)
    {
        memset(dp,0,sizeof(dp));
        cin>>wA>>wB>>wC>>wD;
        for(int i=0;i<=cntA;i++)
        {
            for(int j=0;j<=cntB;j++)
            {
                for(int k=0;k<=cntC;k++)
                {
                    for(int l=0;l<=cntD;l++)
                    {
                        if(i>0)
                        dp[i][j][k][l]=max(dp[i-1][j][k][l]+((fun(i-1,j,k,l))%10)*wA,dp[i][j][k][l]);
                        if(j>0)
                        dp[i][j][k][l]=max(dp[i][j-1][k][l]+((fun(i,j-1,k,l))%10)*wB,dp[i][j][k][l]);
                        if(k>0)
                        dp[i][j][k][l]=max(dp[i][j][k-1][l]+((fun(i,j,k-1,l))%10)*wC,dp[i][j][k][l]);
                        if(l>0)
                        dp[i][j][k][l]=max(dp[i][j][k][l-1]+((fun(i,j,k,l-1))%10)*wD,dp[i][j][k][l]);
                    }
                }
            }
        }
        cout<<dp[cntA][cntB][cntC][cntD]<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值