题目链接
题面
题面翻译
题目背景
在2214年的的 “Russian代码杯” 的决赛选手将是在淘汰赛中的获胜者。
题目描述
两种形式的选拔赛 淘汰赛有两种形式,我们把他叫正常赛与特殊赛,正常赛中的题目为
c
c
c 道,获胜的
n
n
n 个人可以参加决赛。特殊赛题目为
d
d
d 道,获胜的
1
1
1 个人可参加决赛。此外,有
k
k
k 位大佬拥有报送名额,不用参加淘汰赛。(黑幕)
组委会需要你组织好各轮淘汰赛,比赛用到的题目要最少,但是保证在所有淘汰赛结束后,有
n
×
m
n\times m
n×m 位选手进入决赛。
输入格式
第1行输入
c
c
c 和
d
d
d
(
1
<
=
c
,
d
<
=
100
)
(1<=c,d<=100)
(1<=c,d<=100)
第2行输入
n
n
n 和
m
m
m(1<=n,m<=100)$
第3行输入
k
k
k
(
1
<
=
k
<
=
100
)
(1<=k<=100)
(1<=k<=100)(
c
,
d
,
n
,
m
,
k
c,d,n,m,k
c,d,n,m,k为正整数)
输出格式
输出最少需要多少道题目
题目描述
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
c
c problems, the winners of the round are the first
n
n
n people in the rating list. Each of the additional elimination rounds consists of
d
d
d problems. The winner of the additional round is one person. Besides,
k
k
k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least
n
×
m
n\times m
n×m people should go to the finals. You need to organize elimination rounds in such a way, that at least
n
×
m
n\times m
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 c c and d d d ( 1 < = c , d < = 100 1<=c,d<=100 1<=c,d<=100 ) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n n nand m m m ( 1 < = n , m < = 100 1<=n,m<=100 1<=n,m<=100 ). Finally, the third line contains an integer k k k ( 1 < = k < = 100 1<=k<=100 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
样例输入 #1
1 10
7 2
1
样例输出 #1
2
样例 #2
样例输入 #2
2 2
2 1
2
样例输出 #2
0
题意
- 需要 n × m n\times m n×m 名选手晋级,其中有 k k k 名选手保送,求最少需要多少道题目
- 淘汰赛有两种模式
- 正常赛,晋级 n n n 人,需要 c c c 道题目
- 特殊赛,晋级 1 1 1 人,需要 d d d 道题目
思路
这道题考察了对完全背包的理解、将文本翻译成模型的能力
一看题,看不出什么算法
可是只要我们将淘汰赛模式视为阶段,将人视为重量,将题目数量视为花费
那此题就转化为:在满足背包里有
n
×
m
−
k
n\times m-k
n×m−k 个重量单位(因为有
k
k
k 名保送选手)前提下,求最小花费
那这题就变成了一道完全背包
状态转移方程也能得到
d p [ j ] = m i n ( d p [ j − w [ i ] ] + v [ i ] , d p [ j ] ) ; dp[j]=min(dp[j-w[i]]+v[i],dp[j]); dp[j]=min(dp[j−w[i]]+v[i],dp[j]);
w [ i ] w[i] w[i] 代表人(重量)
v [ i ] v[i] v[i] 代表题目(花费)
因为是求最小花费,所以在
d
p
dp
dp 前要将
d
p
[
i
]
=
∞
,
d
p
[
0
]
=
0
dp[i]=\infty\ ,\ dp[0]=0
dp[i]=∞ , dp[0]=0
A
C
AC
AC 代码如下
#include<bits/stdc++.h>
using namespace std;
#define int long long
int c,d,n,m,k,w[5],v[5],dp[10010],ans=0x7fffffff;
signed main(){
scanf("%lld%lld%lld%lld%lld",&c,&d,&n,&m,&k);
w[1]=n,v[1]=c,w[2]=1,v[2]=d;//初始化
memset(dp,127,sizeof(dp));//初始化
dp[0]=0;//初始化
for(int i=1;i<=2;i++)//以两种淘汰赛模式为阶段
for(int j=w[i];j<=10000;j++)//完全背包——从前往后
dp[j]=min(dp[j-w[i]]+v[i],dp[j]);//状态转移方程
for(int i=n*m-k;i<=10000;i++)ans=min(ans,dp[i]);//题目没说晋级人数要恰好等于n*m-k,所以超出一些也是可以的
printf("%lld",ans<0?0:ans);//特判ans为负值时,不用出题就可以满足晋级人数
return 0;
}