2018年上海金马五校程序设计竞赛 Problem B : Ball Game

Problem B : Ball Game


Submit (Out of Contest)

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

 


题意:很绕,慢慢读题吧。第一个样例 =  0 + 2*3 +5*4 +9*5 =71  ,即按顺序放。


解题思路:4维DP。跟那个从左上角走到走下角,求最大价值那题很像,这里变成4维了。递推公式是一样的。然后价值相等的时候要尽量使得最后一位最大。


#include<iostream>
#include<bitset>
#include<string.h>
#include<vector>
using namespace std;
typedef long long int ll;
const int MAXN=1200;
 
int dp[35][35][35][35];
int w[35][35][35][35];
 
int main(){
 
    int A,B,C,D;
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&A,&B,&C,&D)){
 
        scanf("%d%d%d%d",&a,&b,&c,&d);
        memset(dp,0,sizeof(dp));
memset(w,0,sizeof(w));
 
        for(int i=0;i<=A;i++)
            for(int j=0;j<=B;j++)
                for(int k=0;k<=C;k++)
                    for(int l=0;l<=D;l++){
 
                        if(w[i][j][k][l] * a + dp[i][j][k][l] > dp[i+1][j][k][l]){
                            dp[i+1][j][k][l]=w[i][j][k][l] * a + dp[i][j][k][l];
                            w[i+1][j][k][l]=(w[i][j][k][l]+a)%10;
                        }
                        else{
                            if(w[i][j][k][l] * a + dp[i][j][k][l] == dp[i+1][j][k][l]){
                                w[i+1][j][k][l]=max((w[i][j][k][l]+a)%10,w[i+1][j][k][l]);
                            }
                        }
 
 
                        if(w[i][j][k][l] * b + dp[i][j][k][l] > dp[i][j+1][k][l]){
                            dp[i][j+1][k][l]=w[i][j][k][l] * b + dp[i][j][k][l];
                            w[i][j+1][k][l]=(w[i][j][k][l]+b)%10;
                        }
                        else{
                            if(w[i][j][k][l] * b + dp[i][j][k][l] == dp[i][j+1][k][l]){
                                w[i][j+1][k][l]=max((w[i][j][k][l]+b)%10,w[i][j+1][k][l]);
                            }
                        }
 
 
                        if(w[i][j][k][l] * c + dp[i][j][k][l] > dp[i][j][k+1][l]){
                            dp[i][j][k+1][l]=w[i][j][k][l] * c + dp[i][j][k][l];
                            w[i][j][k+1][l]=(w[i][j][k][l]+c)%10;
                        }
                        else{
                            if(w[i][j][k][l] * c + dp[i][j][k][l] == dp[i][j][k+1][l]){
                                w[i][j][k+1][l]=max((w[i][j][k][l]+c)%10,w[i][j][k+1][l]);
                            }
                        }
 
 
                        if(w[i][j][k][l] * d + dp[i][j][k][l] > dp[i][j][k][l+1]){
                            dp[i][j][k][l+1]=w[i][j][k][l] * d + dp[i][j][k][l];
                            w[i][j][k][l+1]=(w[i][j][k][l]+d)%10;
                        }
                        else{
                            if(w[i][j][k][l] * d + dp[i][j][k][l] == dp[i][j][k][l+1]){
                                w[i][j][k][l+1]=max((w[i][j][k][l]+d)%10,w[i][j][k][l+1]);
                            }
                        }
 
                    }
 
 
         printf("%d\n",dp[A][B][C][D]);
 
 
 
    }
    return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值