http://acm.hdu.edu.cn/showproblem.php?pid=1789
这题贪心 每次找分数最多的看能不能全部完成 不能的话就舍去 去找下一个
这个我还真没想到 看题解才知道 这题隐蔽性真大 还有就是判断能不能全部完成那里 我卡主了 蛋疼
代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;
struct node
{
int deadline;
int score;
}num[1005];
bool operator <(const node a,const node b)
{
if(a.score==b.score)
return a.deadline<b.deadline;
return a.score>b.score;
}
int hashs[10005];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&num[i].deadline);
for(int i=1;i<=n;i++)
scanf("%d",&num[i].score);
sort(num+1,num+1+n);
int ans=0;
memset(hashs,0,sizeof(hashs));
for(int i=1;i<=n;i++)
{
for(int j=num[i].deadline;j>0;j--)
{
if(!hashs[j])
{
hashs[j]=1;
break;
}
if(j==1)
ans+=num[i].score;
}
}
printf("%d\n",ans);
}
}