传送门
题目描述
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.
思路
这题可以说是非常水了,转化一下题意,可以看出,是一个裸的完全背包问题,要求至少选出n*m-k个人,而物体总共有2种,一种是普通比赛,w为n,v为c,另一种为附加赛,w为1,v为d,所以直接完全背包就可以了= ̄ω ̄=
一个小细节
没有严格要求选n*m-k个人,所以选的人数大于等于n*m-k即可,所以最后出答案的时候要把dp数组扫一遍。
附上代码
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[10050]; int v[5]; int w[5]; int main(){ for(register int i=0;i<=10049;i++){ dp[i]=99999999; } int c,d; int n,m; int k; cin>>c>>d; cin>>n>>m; cin>>k; dp[0]=0; w[1]=n; w[2]=1; v[1]=c; v[2]=d; for(register int i=1;i<=2;i++){ for(register int j=w[i];j<=10049;j++){ dp[j]=min(dp[j],dp[j-w[i]]+v[i]); } } int ans=99999999; for(register int i=m*n-k;i<=10049;i++){ ans=min(dp[i],ans); } cout<<ans<<endl; }