Description
Zplinti1 is a student in UESTC, a school full of beautiful girls. As a diligent boy, he has no interest in girls and just wants to study hard and gets a good remark when graduating, so that he can get a postgraduate recommendation, which means he can directly to continue his study for post-graduate session without taking exams.
The policy for a postgraduate recommendation in UESTC is as follows:
1. The Base Score. That is the weighted mean score for all compulsory courses. You have n such courses, each with a full mark as 100 points. The Base Score is calculated in this way: for each course i, there is a weight as B[i], and suppose your score is A[i]. Then the Base Score P is calculated as sigma(A[i]*B[i])/sigma(B[i]).Please note that all A[i] must be no less than 60, otherwise you can’t get the recommendation.
2. Attending other contests can bring extra points. First Prize – 3 points, Second Prize – 2 points, and Third Prize – 1 point. The points are directly added to the Base Score. A student can attend at most 2 contests.
Here is how zplinti1 studies in UESTC:
1. For each course i, zplinti1 has an array time[i][X], which is the time he needs to study to improve his result on the course, from 10*Xpoints to 10*(X+1) points.
2. Zplinti1 finds, after taking a certain contest, it is easier for him to study some courses. In other word, it will affect his initial score for some courses. Here, initial score of a course means the score he will get without paying any time studying that course. If he doesn’t attend any contests, the initial score for every course should be zero.
The new policy of UESTC gives students more freedom: They can study all the four-year’s courses freely, which means they can arrange their time as they like, study the courses in any order, as long as they finish all the courses in a certain time. The contest can be arranged freely also.
Zplinti1 wants to know his highest possible score, if he makes a proper plan. Zplinti1 cannot do multiple things at the same time, i.e. he can only learn a single course or participate in a single contest at the same time.
Input
The first line of input contains a number T, indicating the number of test cases. (T<=30).
For each case, the first line are two integers n and sum (1<=n<=100,1<= sum<=1000), means that there are n courses and zplinti1 has sum time to study in total. Following n lines, each line comes an integer B[i] first, followed by ten integers time[i][j]. (0<= i <n,0<= j="" <10,1<="time[i][j]<=5,1<=B[i]<=5)<br">
Next six lines describe the two contests. For each contest, the kth line comes with an integer pt[k] at first, which means that if zplinti1 wants to get k points in this contest he needs to spend pt[k] time. Then followed by n integers base[k][t], which means that for course t, its initial score will become 10*base[k][t], if zplinti1 gets k points in this contest.(1<= k <=3,0<= t < n,1<= pt[k] <= 1000,0<= base[k][t] <=10)
Output
For each case, output “Case #i: “ first. (i is the number of the test case, from 1 to T). Then output highest possible score zplinti1 can get(round to two decimal places). If zplinti1 can’t get the recommendation output “Impossible” instead.
Sample Input
3
1 9
2 1 1 1 1 1 2 2 2 2 2
4 2
5 3
7 5
3 1
5 4
6 6
1 10
2 5 5 5 5 5 5 5 5 5 5
5 0
10 0
15 0
5 1
10 2
15 3
2 20
2 1 1 1 1 1 1 1 1 1 1
3 2 2 2 2 2 2 2 2 2 2
6 1 2
9 2 3
14 3 5
5 2 1
8 3 2
15 5 4
Sample Output
Case #1: 73.00
Case #2: Impossible
Case #3: 68.00
Hint
If zplinti1 has attended both two contests, and those two contests’ influence on a course’s initial score is different, we will take the higher one.
For example, if in the first contest, base[k1][t]=7, and in the second contest, base[k2][t]=8, then if zplinti1 has got k1 points in the 1st contest and k2 points in the 2nd contest, his initial score for course t will be 80.
题目其实不难,就是比较长,把各种关系撸顺了,就比较容易理解了。自己看
比赛的时候wa了,今天看了一上午(没听课),还是没过,中午队友找到bug了。多了一个万恶的“=”。
思路都在代码里了,自己夸自己一下,注释得到了队友的赞美。
其实这题没过责任在我,dp的时候sum<0是不合法的,但是我写成了sum<=0,如果时间都用来做竞赛的话,最后没时间学习,这个状态也是合法的,所以不能有等于号。
这一上午,我自己写了生成数据的代码,找了AC代码,不断生成答案,对比答案,还是没找到错。
以后写题思维要清晰!!!!!!!!
中午可以睡个好觉了。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
/*课程是从0开始的*/
int allTime=0;//所有的时间
int T,n,sum;//n课程,sum是剩余时间
int B[110],sb;//课程的权值,权值和
int Time[110][15];//提高的费用
int score[110];//每门课程的成绩
int dp[110][1005];//处理到第i门课的时候,还有j个时间,所增加的加权值的最大
double ans;//答案
struct node
{
int pk[4];//0,1,2,3分需要的时间,0分时不参加
int base[4][110];//对成绩的影响
}contest[2];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&T);
for(int cas=1; cas<=T; cas++)
{
memset(score,0,sizeof(score));//初始成绩是0
scanf("%d %d",&n,&allTime);
sb=0;
ans=0;
for(int i=0; i<n; i++)
{
scanf("%d",&B[i]);//权值
sb+=B[i];
for(int j=0; j<10; j++) //提高需要的时间
scanf("%d",&Time[i][j]);
}
for(int i=0; i<2; i++) //两个竞赛
{
contest[i].pk[0]=0;//没参加,需要的时间是0,影响是0
memset(contest[i].base[0],0,sizeof(contest[i].base[0]));
for(int j=1; j<=3; j++) //j等奖
{
scanf("%d",&contest[i].pk[j]);//得j分需要的时间
for(int k=0; k<n; k++)
scanf("%d",&contest[i].base[j][k]);//对每一门课的影响
}
}
for(int c0=0; c0<=3; c0++)
for(int c1=0; c1<=3; c1++) //contest[0]得c0分,contest[1]得c1分,
{
/***************做竞赛******************/
sum=allTime;
sum-=contest[0].pk[c0];
sum-=contest[1].pk[c1];
for(int i=0; i<n; i++)
score[i]=max(contest[0].base[c0][i],contest[1].base[c1][i]);//取最大值
/***************都搞到60分以上**********/
for(int i=0; i<n; i++)
for(; score[i]<6; score[i]++)
sum-=Time[i][score[i]];
int all=0;
for(int i=0; i<n; i++)
all+=score[i]*B[i];
if(sum<=0)//不合法
continue;
/******************DP*******************/
memset(dp,0,sizeof(dp));
//cout<<"Time:"<<sum<<endl;
//cout<<"score:"<<all<<endl;
for(int i = 0; i<n; i++)//第i门课程刷分
{
for(int j = 0; j<=sum; j++)//还有j个时间
{
for(int k = score[i]; k<=10; k++)//刷到k分
{
int need=0;
for(int temp=score[i]; temp<k; temp++)
need+=Time[i][temp];
if(j>=need)
dp[i+1][j-need]=max(dp[i+1][j-need],dp[i][j]+B[i]*(k-score[i]));
}
//cout<<dp[i][j]<<" ";
}
//cout<<endl;
}
for(int j=0; j<=sum; j++)
ans=max(ans,(dp[n][j]+all)*10/(double)sb+c0+c1);
}
if(ans==0)
printf("Case #%d: Impossible\n",cas);
else
printf("Case #%d: %.2f\n",cas,ans);
}
return 0;
}
水平有限,众神轻喷。