Getting a good bonus!
总提交 : 57 测试通过 : 32
比赛描述
Edward is the project manager of Cha-Cha-Cha (Sam-Cha) Software Company International gets many software projects to develop from SIPA. Each software project carries one score, plus a bonus if submitted within a specified number of weeks. The deadline to get the bonus and the number of bonus scores are different for each project. For example, if a project has a deadline of 6 weeks and carries bonus 10 scores, then it earns 10 bonus scores if it is submitted before the end of the 6th week. Each project takes exactly one week to complete. For instance, suppose there are seven projects with deadlines and bonuses as follows:
Project number |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Deadline for bonus | ![]() ![]() 1 | ![]() 1 | ![]() 3 | ![]() 3 | ![]() 2 | ![]() 2 | ![]() 6 |
Bonus score | ![]() ![]() 6 ![]() ![]() | ![]() 7 ![]() | ![]() 3 ![]() | ![]() 1 ![]() | ![]() 4 ![]() | ![]() 5 ![]() | ![]() 1 ![]() |
The maximum bonus score is 16, which can be achieved by completing the projects in the sequence 2,6,3,1,7,5,4.
Note that there are also other sequences that achieve the same score. Your task is to find a schedule to complete all software projects so as to maximize bonus score.
输入
The first line contains an integer N (1 N 50) which determines number of the test cases. The following line is to indicate M (1 M 24), where M is the number of software projects. This is followed by M lines, each containing two integers. The first integer is the deadline for the i thproject and the second integer is the bonus score assigned to the ith projects, (1 i M)
输出
For each test case, print out the maximum score that can be obtained.
样例输入
2
7
1 6
1 7
3 2
3 1
2 4
2 5
6 1
4
2 10
1 9
2 7
7 1
样例输出
15
20
提示
用于NUPT ACM 2010 Personal Ranking Contest 5
题目来源
ACM-ICPC Thailand Southern Area Programming Contest 2010
#include<stdio.h>
int main(){
int N,M,i,j,sum,maxIndex;
int deadline[25],score[25];
bool visited[25];
scanf("%d",&N);
while(N--){
scanf("%d",&M);
for(i=1; i<=M; i++){
scanf("%d%d",deadline+i,score+i);
visited[i] = 0;
}
sum = 0;
for(i=M; i>0; i--){
maxIndex = 0;
for(j=1; j<=M; j++){
if(!visited[j] && deadline[j]>=i && (0==maxIndex||score[j]>score[maxIndex])){
maxIndex = j;
}
}
if(maxIndex){
sum += score[maxIndex];
visited[maxIndex] = 1;
}
}
printf("%d\n",sum);
}
}