Elimination

来源:互联网 发布:二战意大利知乎 编辑:程序博客网 时间:2024/06/05 09:45

完全背包的题目,代码实现并不难,但是要理解题意,英语是硬伤~

题意(人工翻译):

赢得其中一场淘汰赛的选手将会入围2214年的"Russian Code Cup"比赛

淘汰赛的赛制分为初赛和复赛,每场初赛都有c道问题,初赛的获胜者是排名前n位的选手,每场复赛的都有d道题目,复赛的获胜者只有一名,另外,在过去的决赛获胜的k名选手直接被邀请参加决赛而不用淘汰赛

在所有的的淘汰赛结束之后应该有不少于n*m位选手进入决赛,你应该按照这样的规则去组织淘汰赛:不少于n*m位选手去参加决赛,在所有淘汰赛中用的题目应该尽量少

n*m为背包容量,需要的题目数量作为value,比赛通过的人数作为weight,如果人数不够比赛就要一直进行下去,所以符合完全背包的特性,唯一的难点就是需要在n*m-k~n*m的范围内找一个最小值,只要通过的人数超过n*m即可,然而为什么是这个范围,首先n*m-k是下界这个不必多说,一场比赛是否被选择取决于里面每道题目的“价值”,这场比赛通过人数除以题目数量(不是取整除法),而只有两种比赛要么初赛“价值”高,要么复赛“价值”高,若初赛“价值”高,因为初赛每次通过n名选手,至少要通过n*m名选手,所以上界选取n*m,而复赛“价值”高则对应下界(所以根据这个还有另外的写法点击打开链接)

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 107 21
Output
2
Input
2 22 12
Output
0

#include<stdio.h>#include<string.h>#include<algorithm>#define maxn 105#define inf 0x3f3f3f3fusing namespace std;int main(){int vol[2]={0},val[2]={0},n,m,k,ans=inf,dp[maxn*maxn];scanf("%d%d%d%d%d",&val[0],&val[1],&n,&m,&k);if(k>=n*m)printf("0");else{vol[0]=n;vol[1]=1;memset(dp,inf,sizeof(dp));dp[0]=0;for(int i=0;i<2;i++){for(int j=vol[i];j<=n*m;j++){if(dp[j-vol[i]]!=inf)dp[j]=min(dp[j],dp[j-vol[i]]+val[i]);}}for(int i=n*m-k;i<=n*m;i++)ans=min(ans,dp[i]);printf("%d",ans);}return 0;}

原创粉丝点击