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. 初次改app

    没有学过安卓,突然需要改app里的一个bug,一个没搞过安卓的人要怎么入手去改这个安卓的代码呢?下面看看我入手的步骤 首先,页面上有几个文字“曲线分析”,那么在项目里找到这个文字,就可以找到这个页面的 ...

  2. 课外作业(建立double类型的小数,按照四舍五入保留2位小数)

    举例:

  3. CAD交互绘制文字(网页版)

    在CAD设计时,需要绘制文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawText 绘制一个单行文字.详细说明如下: 参数 说明 DOUBLE dPosX ...

  4. vue.js中的表单radio,select,textarea的v-model属性的用法

    只要是表单元素,其值已经不会再用value来定义了,但是placeholder还是可以用来设置默认值. section1--input:type="text" type=" ...

  5. sqlserver差异备份3117

    1.出现错误"3117" 2.完整备份/选项/不对数据库执行任何操作 3.数据库显示"正在还原" 4.差异备份/选项/回滚 5.数据库完整备份与差异备份成功

  6. 15. PARTITIONS

    15. PARTITIONS PARTITIONS表提供有关表分区的信息. 此表中的每一行对应于分区表的单个分区或子分区. 有关分区表的更多信息,请参见分区. PARTITIONS表有以下列: TAB ...

  7. js事件默认行为

    事件默认行为: 当一个事件发生的时候浏览器自己默认做的事情 怎么阻止? 当前这个行为是什么事件触发的,然后在这个事件的处理函数中使用 return false; 但是return false 阻止的是 ...

  8. mysql EXPLAIN Join Types 手册解释 及数据实操

     第一部分:名称解释 文档地址 https://dev.mysql.com/doc/refman/5.7/en/explain-output.html EXPLAIN Join Types: The ...

  9. python-爬虫学习(文字、图片、视频)

    爬虫-文字爬取 import re import requests respone = requests.get('https://ishuo.cn/') ##获取网站url data = respo ...

  10. Python数据分析 Pandas模块 基础数据结构与简介(一)

    pandas 入门 简介 pandas 组成 = 数据面板 + 数据分析工具 poandas 把数组分为3类 一维矩阵:Series 把ndarray强大在可以存储任意数据类型可以专门处理时间数据 二 ...