首页 > 代码库 > Doing Homework again
Doing Homework again
Doing Homework again |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 81 Accepted Submission(s): 75 |
Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score. |
Input The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow. Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores. |
Output For each test case, you should output the smallest total reduced score, one line per test case. |
Sample Input 333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4 |
Sample Output 035 |
Author lcy |
Source 2007省赛集训队练习赛(10)_以此感谢DOOMIII |
Recommend lcy |
/*题意:给你每门功课要交的最后期限,并且延期一天所扣的分数,现在让你安排一下写作业的顺序,使扣的分数最少初步思路:状压DP。。。。。。1000不可能状压的#补充:想的太复杂了,想起来以前做过用状压,贪心就可以搞,从最后一天开始搞,每次尽可能选择扣分多的。*/#include<bits/stdc++.h>using namespace std;struct node{ int tim; int scor; node(){} node(int a,int b){ tim=a; scor=b; } bool operator <(const node &other) const{ if(tim!=other.tim) return tim>other.tim; return scor>other.scor; }};node fr[1010];int Time[1010],Score[1010];int vis[1010];//记录写过的作业int t;int n;void init(){ memset(vis,0,sizeof vis);}int main(){ // freopen("in.txt","r",stdin); scanf("%d",&t); while(t--){ init(); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&fr[i].tim); } int res=0;//扣得总分 for(int i=0;i<n;i++){ scanf("%d",&fr[i].scor); res+=fr[i].scor; } sort(fr,fr+n); for(int i=fr[0].tim;i>=1;i--){ int max_scor=0; int max_id; for(int j=0;j<n;j++){ if(fr[j].tim<i) break; if(!vis[j]&&fr[j].scor>max_scor){ max_scor=fr[j].scor; max_id=j; } } res-=max_scor; vis[max_id]=1; } printf("%d\n",res); } return 0;}
Doing Homework again
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。