Elimination

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

题意(人工翻译):

赢得其中一场淘汰赛的选手将会入围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 10
7 2
1
Output
2
Input
2 2
2 1
2
Output
0

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 105
#define inf 0x3f3f3f3f
using 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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
naive gaussian elimination(朴素高斯消元法)是一种用于求解线性方程组的简单而直观的方法。它的基本思想是通过逐步消元将方程组转化为上三角形式,然后通过回代求解出未知数的值。 具体来说,朴素高斯消元法首先通过选取一个主元素(通常选择当前列绝对值最大的元素)来消去其他行的相应元素。消元的过程,我们将当前行除以主元素得到一个系数,然后将该系数乘以其他行的相应元素并与当前行相减,以此达到将其他行的相应元素消为0的目的。这个过程循环进行,直到将整个方程组转化为上三角矩阵的形式。 在得到上三角矩阵后,我们可以通过回代的方式求解出未知数的值。回代的过程从最后一行开始,将已知的未知数代入方程式,通过代入来求解出当前行的未知数。然后逐步向上代入求解出其他未知数,最终得到整个方程组的解。 朴素高斯消元法的优点是操作简单、容易理解,适用于小规模的线性方程组。然而,它也有一些缺点。首先,如果某个主元为0,那么消元的过程会出现除0的操作,导致计算错误。其次,如果某些系数非常小,由于计算机的精度限制,可能导致结果的误差较大。 综上所述,朴素高斯消元法是一种简单而直观的方法,适用于小规模的线性方程组求解。然而,在处理较大规模或复杂方程组时,可能需要借助其他更高效、稳定的算法来进行求解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值