This problem is a simple greedy problem, the topic is to be deducted at least the score, then we should try to get the most points. First, the data is sorted in the order of the scores from large to small (if the same is deadline from small to large rows),
The maximum score is then assigned to the last day of the deadline, and if the day has been scheduled, it is scheduled for one day until it cannot be scheduled, then the sum is added.
#include"iostream"#include"algorithm"#include"stdio.h"#include"string.h"#include"Cmath"#defineMX 1005using namespacestd;structnode{intdeadline; intscore;} IGNATIUS[MX];intDONE[MX];BOOLcmpConstNode A,ConstNode B) { if(A.score!=b.score)returnA.score>B.score; Else if(A.deadline!=b.deadline)returna.deadline<B.deadline;}intMain () {intT; CIN>>T; while(t--) { intn,i,j; CIN>>N; for(i=1; i<=n;i++) cin>>Ignatius[i].deadline; for(i=1; i<=n;i++) cin>>Ignatius[i].score; memset (Done,0,sizeof(done)); Sort (Ignatius+1, ignatius+n+1, CMP); intsum=0; for(i=1; i<=n;i++) { if(!done[ignatius[i].deadline]) done[ignatius[i].deadline]=1; Else { for(j=ignatius[i].deadline-1; j>=1; j--) { if(!done[j]) {done[j]=1; Break;} } if(j<=0) sum+=Ignatius[i].score; }} cout<<sum<<Endl; } return 0;}View Code
HDU 1789 Doing Homework again