uva 11341 Term Strategy (DP)

来源:互联网 发布:.mobi算不算顶级域名 编辑:程序博客网 时间:2024/06/05 19:17

B - Term Strategy

Time Limit: 1 sec
Memory Limit: 16MB

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

Peter has N (1 <= N <= 10) courses, because he completely failed theprevious term exams so he has to pass them too. He is already late with hisexams and the deadline is coming. He agreed with all teachers to pass all theexams in one day. The idea he followed is - "Everything or nothing". After hemade some considerations and an assumption that we'll play billiard only 5 hoursa day, he counted the number of hours he has left to get himself prepared forexams. 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 ispreparing for. Because of this difficult task he's preparing for at least onehour 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 receiveat least 5. Also Peter is a greedy person and he wants to have the highestaverage mark that is possible.

As Peter is perfectly aware of his abilities he made a table L. Each line of thistable represents a course and each column represents a number of hours Peter ispreparing for a particular exam. Element Lij of the table means, that for i-thexam Peter devotes j-th hours of his available time. It is known that the morePeter 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 personhe remembered. So as he is completely desperate he asks for your help! Help Peterin 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 lineof each test contains two integers N and M. Then N lines follow each containingM integers which define Li j element.

OUTPUT:

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

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

SAMPLE INPUT:

24 55 5 6 7 85 5 6 7 85 6 7 8 86 7 8 9 94 54 5 6 7 84 5 6 7 85 6 7 8 86 7 8 9 9

SAMPLE OUTPUT:

Maximal possible average mark - 5.50.Peter, you shouldn't have played billiard that much.
#include <iostream>#include <cstdio>using namespace std;#define ll long longconst int maxn = 110;ll dp[20][maxn][maxn],mp[20][maxn];int N , M;void initial(){for(int i = 0;i < 20;i++){for(int j = 0;j < maxn;j++){for(int k = 0;k < maxn;k++){dp[i][j][k] = -1;}mp[i][j] = 0;}}}void readcase(){cin >> N >> M;for(int i = 1;i <= N;i++){for(int j = 1;j <= M;j++){cin >> mp[i][j];//cout << i << " : " << j << " = " << mp[i][j] << endl;}}}ll DP(int c, int m , int t){if(c >= N){//cout << c << " " << t << endl;if(mp[c][m] >= 5){return mp[c][m];}else{return 0;}}if(t-m <= 0) return 0;if(dp[c][m][t] != -1) return dp[c][m][t];ll ans = 0;for(int i = 1;i <= t-m;i++){if(mp[c+1][i] >= 5){int tem = DP(c+1 , i , t-m);if(tem != 0){ans = max(ans , mp[c][m]+tem);}}}return dp[c][m][t] = ans;}void computing(){ll ans = 0;for(int i = 1;i <= M;i++){if(mp[1][i] >= 5){ans = max(ans , DP(1 , i , M));}}if(ans > 0){printf("Maximal possible average mark - %.2lf.\n" , (1e-9+ans)/N);//WA:(1.0*ans)/N}else{printf("Peter, you shouldn't have played billiard that much.\n");}}int main(){//freopen("in" , "r" , stdin);int t;cin >> t;while(t--){initial();readcase();computing();}return 0;}

 
0 0