Educational Codeforces Round 28 B: Math Show

本文介绍了一种解决特定数学竞赛问题的策略。在这个问题中,参与者需要完成一系列由子任务构成的任务,以获得最大化的积分奖励。文章详细解释了如何通过枚举和贪心算法来确定最优的完成顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Math Show

Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered1 throughk. It takes himtj minutes to solve thej-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.

By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarpcompletely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task isk + 1.

Polycarp has M minutes of time. What is the maximum number of points he can earn?

Input

The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).

The second line contains k integer numbers, valuestj (1 ≤ tj ≤ 1000000), wheretj is the time in minutes required to solvej-th subtask of any task.

Output

Print the maximum amount of points Polycarp can earn inM minutes.




       题意:  给定你 n 个相同任务, 每个包含 k  个小任务,从1 到 k ,  n 个相同任务 的 完成时间相同, 但每个小任务的完成时间不相同。 当你完成了一个大的任务之后,ans 在原来的基础上加1 ; 让你求 max  ->  ans;


       思路:  本来考虑是 dp 的,然而不会dp ,就想着用贪心求,考虑模拟得到最优的方式吧。

首先枚举   可以完成  i  个大的任务, 然后循环找到从 时间到最大的, 其实就是暴力求解,数据不大。

注意  爆 int  问题。




 

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll A[100];
ll n,k,m;
int main()
{
    while(scanf("%lld%lld%lld",&n,&k,&m)!=EOF)
    {
        ll sum=0;
        for(int i=1;i<=k;++i)
        {
            scanf("%lld",&A[i]);
            sum+=A[i];
        }
        sort(A+1,A+k+1);
        ll ans=0;
        for (int i=0;i<=n && m>=i*sum;++i)
        {
            ll tot=i*(k+1),tem=m-i*sum;
            for(int j=1;j<k;++j)
                for(int p=1;p<=n-i;++p)
                    if(tem>=A[j])
                    {
                        tem-=A[j];
                        tot++;
                    }
            ans=max(ans,tot);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值