UVa11341 Term Strategy

彼得因玩台球错过了所有课程,现在必须在一天内通过10门课程的期末考试。他有M小时来准备,每门考试至少准备1小时。考试按10分制评分,至少得5分才能及格。彼得是个贪婪的人,他希望得到尽可能高的平均分。给定一个矩阵L,表示为每个考试准备不同小时数时的得分,你的任务是帮助彼得制定最佳的复习计划,以达到最高的平均分。

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

B - Term Strategy

Time Limit: 1 sec 
Memory Limit: 16MB

Student Peter was playing billiard all the term and for that reason he missed all his lectures. Unfortunately that's the time for term exams which Peter must pass.

Peter has N (1 <= N <= 10) courses, because he completely failed the previous term exams so he has to pass them too. He is already late with his exams and the deadline is coming. He agreed with all teachers to pass all the exams in one day. The idea he followed is - "Everything or nothing". After he made some considerations and an assumption that we'll play billiard only 5 hours a day, he counted the number of hours he has left to get himself prepared for exams. He has concluded that he has M (0 < M <= 100) hours to get prepared. While he is preparing he has to read at least the name of the subject he is preparing for. Because of this difficult task he's preparing for at least one hour for each exam. If he has no time to prepare for exam - he fails it.

Exam is evaluated using 10-grade system. To pass an exam Peter has to receive at least 5. Also Peter is a greedy person and he wants to have the highest average mark that is possible.

As Peter is perfectly aware of his abilities he made a table L. Each line of this table represents a course and each column represents a number of hours Peter is preparing for a particular exam. Element Lij of the table means, that for i-th exam Peter devotes j-th hours of his available time. It is known that the more Peter is getting prepared for a particular exam the highest mark he receives, i.e. Li j = Li j+1 for each 1 <= i <= N ir 1 <= j <= M - 1.

Suddenly Peter remembers that he has a good friend. You're actually the person he remembered. So as he is completely desperate he asks for your help! Help Peter in his mission of passing exams and achieving the maximum possible average mark.

INPUT:
The number of tests T (T < 100) is given on the first line of input. First line of each test contains two integers N and M. Then N lines follow each containing M integers which define Li j element.

OUTPUT:
For each test case find whether Peter passes all exams. If he is that lucky to pass them print line: "Maximal possible average mark - S." (The result must be rounded to 2 digits after decimal point).

In case when he is not that lucky, and he has at least one exam that he`s unable to pass in given time limits print a line "Peter, you shouldn`t have played billiard that much.".

SAMPLE INPUT:
2
4 5
5 5 6 7 8
5 5 6 7 8
5 6 7 8 8
6 7 8 9 9
4 5
4 5 6 7 8
4 5 6 7 8
5 6 7 8 8
6 7 8 9 9

SAMPLE OUTPUT:

Maximal possible average mark - 5.50.
Peter, you shouldn't have played billiard that much.

DP题,用记忆化搜索可以完美解决,一个细节在于  printf("Maximal possible average mark - %.2lf.\n",ans*1.0/n+1e-9);  在UVa论坛上看到的!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
int n,m;
int gra[12][110];
int dp[12][110];
int dfs(int dep,int tot){
    if(dep==n+1)
        return 0;
    if(dp[dep][tot] != -1)
        return dp[dep][tot];
    int ans = -10000000;
    for(int i = 1; i <= tot; i++)
        if(gra[dep][i]>=5) ans = max(ans,dfs(dep+1,tot-i)+gra[dep][i]);
    return dp[dep][tot] = ans;
}
int main(){
    int ncase;
   // freopen("in","r",stdin);
    cin >> ncase;
    while(ncase--){
        scanf("%d%d",&n,&m);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) scanf("%d",&gra[i][j]);
        memset(dp,-1,sizeof dp);
        int ans = dfs(1,m);
        if(ans < 5*n)
            printf("Peter, you shouldn't have played billiard that much.\n");
        else
            printf("Maximal possible average mark - %.2lf.\n",ans*1.0/n+1e-9);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值