Skip the Class
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 123 Accepted Submission(s): 73
Problem Description
Finally term begins. luras loves school so much as she could skip the class happily again.(wtf?)
Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).
For every lesson, it has its own type and value to skip.
But the only thing to note here is that luras can't skip the same type lesson more than twice.
Which means if she have escaped the class type twice, she has to take all other lessons of this type.
Now please answer the highest value luras can earn if she choose in the best way.
Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).
For every lesson, it has its own type and value to skip.
But the only thing to note here is that luras can't skip the same type lesson more than twice.
Which means if she have escaped the class type twice, she has to take all other lessons of this type.
Now please answer the highest value luras can earn if she choose in the best way.
Input
The first line is an integer T which indicates the case number.
And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.
Then there are n lines, for each line, there is a string consists of letters from 'a' to 'z' which is within the length of 10,
and there is also an integer which is the value of this lesson.
The string indicates the lesson type and the same string stands for the same lesson type.
It is guaranteed that——
T is about 1000
For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000
And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.
Then there are n lines, for each line, there is a string consists of letters from 'a' to 'z' which is within the length of 10,
and there is also an integer which is the value of this lesson.
The string indicates the lesson type and the same string stands for the same lesson type.
It is guaranteed that——
T is about 1000
For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000
Output
As for each case, you need to output a single line.
there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
Sample Input
2 5 english 1 english 2 english 3 math 10 cook 100 2 a 1 a 2
Sample Output
115 3//把相同的课程排序,找最大和次大的#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> using namespace std; int s[105]; int vis[110]; int b[1000]; int main() { int t; scanf("%d",&t); while(t--) { int n; char a[100][100]; scanf("%d",&n); int p; memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) { scanf("%s%d",a[i],&b[i]); } int sum=0; int we; for(int i=0; i<=n-1; i++) { memset(s,0,sizeof(s)); p=0; if(vis[i]==0) { s[p++]=b[i]; for(int j=i+1; j<n; j++) { we=0; int l1; l1=strlen(a[i]); int l2; l2=strlen(a[j]); if(l1==l2) { for(int h=0; h<=l1; h++)//看a[i]和a[j]串是否配对,we=0时就配对 { if(a[i][h]!=a[j][h]) { we=1; } } if(we==0&&vis[j]==0) { s[p++]=b[j]; vis[j]=1; } } } we=0; sort(s,s+p); sum+=s[p-1]; sum+=s[p-2]; vis[i]=1; } } printf("%d\n",sum); } }