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
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
 
Sample Output
0 3 5
 
可以将作业按扣分高低排序,每次找到扣分最高的,将它安排进终止日期那一天,如果那天有事,就在往前推,,如果最后安排不下,就扣分。这样循环n次就可以了。
sort排序。。。。
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#define N 1100
using namespace std; bool hh[N];
typedef struct nod{
int x,y;
}s[N]; bool cmp(nod a,nod b)
{
if(a.y!=b.y)
return a.y>b.y;
else
return b.x>a.x;
}
int main()
{
nod s[N];
int T,n,i,j,sum;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&s[i].x);
}
for(i=;i<=n;i++)
scanf("%d",&s[i].y);
sort(s+,s+n+,cmp);
sum=;
memset(hh,false,sizeof(hh));
for(i=;i<=n;i++)
{
for(j=s[i].x;j>;j--)
{
if(hh[j]==false)
{
hh[j]=true;
break;
}
}
if(j==)
{
sum=sum+s[i].y;
}
}
printf("%d\n",sum);
}
return ;
}

动态规划: HDU 1789Doing Homework again的更多相关文章

  1. HDU——1789Doing Homework again(贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. dp 动态规划 hdu 1003 1087

    动态规划就是寻找最优解的过程 最重要的是找到关系式 hdu 1003 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意:求最大字序列和, ...

  3. 动态规划 hdu 1024

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. 动态规划:HDU1789-Doing Homework again

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu 5243 Homework

    Homework Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. 动态规划 HDU 1176

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. 动态规划-----hdu 1024 (区间连续和)

    给定一个长度为n的区间:求m段连续子区间的和 最大值(其中m段子区间互不相交) 思路: dp[i][j]: 前j个元素i个连续区间最大值 (重要 a[j]必须在最后一个区间内) 转移方程:dp[i][ ...

  8. [ACM_动态规划] hdu 1176 免费馅饼 [变形数塔问题]

    Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁 ...

  9. HDU 1074 Doing Homework (动态规划,位运算)

    HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...

随机推荐

  1. C#调用dll(Java方法)

    因为工作需求,要求用C#直接调用Java方法,下面呢是操作过程以及一些理解,如果有什么理解不对的,欢迎大家指出! 具体操作: 一.将Java写好的Demo以jar包形式导出 package demo; ...

  2. hdu 5402 Travelling Salesman Problem (技巧,未写完)

    题意:给一个n*m的矩阵,每个格子中有一个数字,每个格子仅可以走一次,问从(1,1)走到(n,m) 的路径点权之和. 思路: 想了挺久,就是有个问题不能短时间证明,所以不敢下手. 显然只要n和m其中一 ...

  3. Hibernate中tx.commit()

    hibernate.cfg,xml文件中的自动提交事务是false.主键生成策略是native. 在表的映射继承是手动提交事务(即:tx.commit())无法发出sql语句,把数据插入到数据库的表中 ...

  4. ios之coredata

    Core Data数据持久化是对SQLite的一个升级,它是ios集成的,在说Core Data之前,我们先说说在CoreData中使用的几个类. (1)NSManagedObjectModel(被管 ...

  5. 重载操作符 'operator'

    operator 是 C++ 的(运算符的)重载操作符.用作扩展运算符的功能. 它和运算符一起使用,表示一个运算符函数,理解时应将  [operator+运算符] 整体上视为一个函数名. 要注意的是: ...

  6. IOI2008 Island 岛屿

    题目描述: bz luogu 题解: 裸的基环树直径. 代码: #include<queue> #include<cstdio> #include<cstring> ...

  7. Ahoi2014&Jsoi2014 支线剧情

    题目描述 题解: 每条边至少经过一次,说明经过下界为$1$. 然后套有源汇上下界最小费用可行流板子. 口胡一下. 此类问题的建图通式为: 1.假设原来的边流量上下界为$[l,r]$,那么在新图中建流量 ...

  8. POJ-1163 递推

    代码很容易看明白,就不详解了. 这个是空间优化的代码. #include <iostream> #include <algorithm> #define MAX 101 usi ...

  9. [模板] Miller-Rabin 素数测试

    细节挺多的.. #include<iostream> #include<cstdlib> #include<cstdio> #include<ctime> ...

  10. 利用RestTemplate进行http调用

    在对接API的时候,会涉及调用第三方的服务,这时候可以利用RestTemplate进行调用,下面给大家展示一个简单的调用demo. package com.tanlu.user.api.control ...