码迷,mamicode.com
首页 > 其他好文 > 详细

[CodeForces] 417A Elimination

时间:2018-02-23 00:23:45      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:art   mount   who   without   nts   gpo   ipa   ant   pos   

传送门

codeforces

luogu

题目描述

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;
}

 

[CodeForces] 417A Elimination

标签:art   mount   who   without   nts   gpo   ipa   ant   pos   

原文地址:https://www.cnblogs.com/Fang-Hao/p/8460559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!