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.
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.
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
1 10 7 2 1
2
2 2 2 1 2
0
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define N 2005
using namespace std;
int c,d,n,m,k;
int main()
{
scanf("%d %d %d %d %d",&c,&d,&n,&m,&k);
int sum;
sum=n*m-k;
if(sum<=0){
printf("0\n");
return 0;
}
int ans;
int t=sum/n;
int aa=sum%n;
ans=t*min(c,n*d)+min(aa*d,c);
printf("%d\n",ans);
return 0;
}
在下边再贴上一种背包的代码。
#include <cstdio>
#include <cstring>
#define inf 0x3f3f3f3f
#define N 10005
int f[N],c,d,n,m,k;
inline int min(int x,int y){return x<y?x:y;}
int main()
{
scanf("%d %d %d %d %d",&c,&d,&n,&m,&k);
if(n*m<=k){puts("0");return 0;}
memset(f,inf,sizeof(f));f[0]=0;
for(int i=1;i<=n*m;++i){
if(i>=n) f[i]=f[i-n]+c;
f[i]=min(f[i],f[i-1]+d);
}
for(int i=1;i<=n*m;i++)
{
printf("%d ",f[i]);
}
printf("\n");
int ans=inf;
for(int i=n*m-k;i<=n*m;++i)
if(f[i]<ans) ans=f[i];
printf("%d\n",ans);
return 0;
}