YTU_3314: Math Show(暴力找解域)

Math Show
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-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 Polycarp completely 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 is k + 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, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.

Output
Print the maximum amount of points Polycarp can earn in M minutes.

Examples
input
3 4 11
1 2 3 4
output
6
input
5 5 10
1 2 4 8 16
output

7

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<k;i++)
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 50;
ll a[maxn];
int main(void)
{
    IO
    int n,k;
    ll m;
    cin>>n>>k>>m;
    ll sum= 0;
    rep(i,1,k+1)
    {
        cin>>a[i];
        sum+= a[i];
    }
    sort(a+1,a+k+1);
    ll  cos = 0;     //每一次的初始花销
    int ans = 0;
    int anst= 0;
    rep(t,0,n+1)
    {
        cos=sum*t;   //假设全部完成了t件任务
        if(cos>m) break;
        anst = (k+1)*t;
        rep(i,1,k+1)
        {
            rep(j,0,n-t)   //剩余工作tj的件数
            {
                cos += a[i];
                if (cos > m)
                {
                    i = INF;
                    break;
                }
                anst++;
            }

        }
        ans = max(ans,anst);

    }
    cout<<ans<<endl;

}

猜你喜欢

转载自blog.csdn.net/Achanss/article/details/82706447