Elimination(DP)

本文介绍了一种关于“俄罗斯编程杯”竞赛的策略问题。竞赛包含主要和附加淘汰赛,每轮比赛设置不同数量的问题,目标是确保至少一定数量的选手进入决赛,同时使用尽可能少的题目。文章提供了一个示例代码,用于计算达到目标所需的最少题目数量。

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

The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.

The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.

As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.

Input

The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k (1 ≤ k ≤ 100) — the number of the pre-chosen winners.

Output

In the first line, print a single integer — the minimum number of problems the jury needs to prepare.

Example
Input
1 10
7 2
1
Output
2
Input
2 2
2 1
2
Output
0
代码:;

#include<stdio.h>
#include<algorithm>
#include<string.h>
#define MAX 100000
using namespace std;
int val[MAX];
int w[MAX];
int dp[MAX];
int main(){
    memset(dp,0,sizeof(dp));
    int n,m,c0,d0;
    int a,b,c,d;
    scanf("%d%d%d%d",&n,&m,&c0,&d0);
    int cnt=1,j;
    int k=n/c0;
    for(j=1;j<=k;j++){
        val[cnt]=d0;
        w[cnt++]=c0;
    }
    int i;
    for(i=0;i<m;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        k=min(n/c,a/b);
        for(j=1;j<=k;j++){
           val[cnt]=d;
           w[cnt++]=c;
        }
    }
    for(i=1;i<cnt;i++){
        for(j=n;j>=w[i];j--)
            dp[j]=max(dp[j],dp[j-w[i]]+val[i]);
    }
    printf("%d\n",dp[n]);
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值