题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2670

Girl Love Value

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 795    Accepted Submission(s): 448

Problem Description
Love in college is a happy thing but always have so many pity boys or girls can not find it.
Now a chance is coming for lots of single boys. The Most beautiful and lovely and intelligent girl in HDU,named Kiki want to choose K single boys to travel Jolmo Lungma. You may ask one girls and K boys is not a interesting thing to K boys. But you may not know Kiki have a lot of friends which all are beautiful girl!!!!. Now you must be sure how wonderful things it is if you be choose by Kiki.

Problem is coming, n single boys want to go to travel with Kiki. But Kiki only choose K from them. Kiki every day will choose one single boy, so after K days the choosing will be end. Each boys have a Love value (Li) to Kiki, and also have a other value (Bi), if one boy can not be choose by Kiki his Love value will decrease Bi every day.
Kiki must choose K boys, so she want the total Love value maximum.

Input
The input contains multiple test cases.
First line give the integer n,K (1<=K<=n<=1000)
Second line give n integer Li (Li <= 100000).
Last line give n integer Bi.(Bi<=1000)
Output
Output only one integer about the maximum total Love value Kiki can get by choose K boys.
Sample Input
3 3 10 20 30 4 5 6 4 3 20 30 40 50 2 7 6 5
Sample Output
47 104
题解: 注意在选的这些个人中,肯定是每日损失最大的先选,所以按照损失从大到小排序,然后就是一个简单的0,1排序了。
dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]+a[i]-b[i]*(j-1);
可以压缩成一维的
代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int N = 1010;
 6 int dp[N];
 7 struct Node{
 8     int a;
 9     int b;
10     bool operator < (const Node& tm) const{
11         return b>tm.b;
12     }
13 }node[N];
14 int main()
15 {
16     int n,k;
17     while(~scanf("%d%d",&n,&k))
18     {
19         for(int i = 0; i < n; i++)
20             scanf("%d",&node[i].a);
21         for(int i = 0; i < n; i++)
22             scanf("%d",&node[i].b);
23         memset(dp,0,sizeof(dp));
24         sort(node,node+n);
25         for(int i = 0; i < n; i++)
26         {
27             for(int j = k; j > 0; j--)
28             {
29                 dp[j] = max(dp[j],dp[j-1]+node[i].a-node[i].b*(j-1));
30             }
31         }
32         printf("%d\n",dp[k]);
33     }
34     return 0;
35 }

转载于:https://www.cnblogs.com/shanyr/p/5281593.html

hdu_2670Girl Love Value(dp)相关推荐

  1. dp,sp,px相互转化

    方法一: public int sp2px(float sp) {return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, ...

  2. [JS][dp]题解 | #打家劫舍(一)#

    题解 | #打家劫舍(一)# 题目链接 打家劫舍(一) 题目描述 描述 你是一个经验丰富的小偷,准备偷沿街的一排房间,每个房间都存有一定的现金,为了防止被发现,你不能偷相邻的两家,即,如果偷了第一家, ...

  3. HDU 2084 数塔(DP)(JAVA版)

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. dp cf 20190615

    A. Timofey and a tree 这个不算是dp,就是一个思维题,好难想的思维题,看了题解才写出来的, 把点和边分开,如果一条边的两个点颜色不同就是特殊边,特殊边两边连的点就叫特殊点, 如果 ...

  5. BZOJ 1003[ZJOI2006]物流运输(SPFA+DP)

    Problem 1003. -- [ZJOI2006]物流运输 1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MB Submit ...

  6. [NOI2005]聪聪与可可(期望dp)

    题意:给一张无向图,有一只猫和一只老鼠,猫每秒会向老鼠的方向移动两个单位,若它们的距离为一,那么只会移动一个单位,老鼠会等概率向周围移动一步或不动,求猫抓到老鼠的期望时间. Solution luog ...

  7. Codeforces 903F Clear The Matrix(状态压缩DP)

    题目链接 Clear The Matrix 题意 给定一个$4 * n$的矩形,里面的元素为$'.'$或$'*'$.现在有$4$种正方形可以覆盖掉$'*'$,正方形的边长分别为$1,2,3,4$. 求 ...

  8. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解源码(A.水+暴力,B.dp+栈)

    A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05   最后更新: 2017年2月21日 20:06   时间限制: 1000ms   内存限制: 128M 描述 传说喵哈哈村有三种神 ...

  9. 尼克的任务 dp 洛谷1280

    蒟蒻表示老久没看过dp题目了,,挺水的一道dp题目都没想出来,,, 首先设dp[i]表示从开始到i时间的最大空闲时间,用vector to[x] 表示从x点开始的任务结束时间,cnt[x]表示从x开始 ...

  10. BNUOJ 52305 Around the World 树形dp

    题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52305 Around the World Time Limit: 20000msMemory ...

最新文章

  1. ahjesus 获取当前方法被调用执行的具体位置,包括命名空间和方法
  2. 转:图解C#的值类型,引用类型,栈,堆,ref,out
  3. NLP之word2vec:利用 Wikipedia Text(中文维基百科)语料+Word2vec工具来训练简体中文词向量
  4. CSDN在文章头部添加目录
  5. 《机器学习》 周志华学习笔记第二章 模型评估与选择(课后习题)
  6. 电脑计算器_CPA考生注意!2020考场只允许带这种计算器
  7. 安全开发流程(SDL、微软)
  8. UE4 在游戏中使用Slate
  9. SQL DATEADD (Transact-SQL)根据需要返回时间,
  10. 【Websocket编程】基于libwebsockets实现客户端数据通信
  11. html的实习报告,HTML实习报告
  12. 千万级 PV是什么意思?
  13. linux系统 插上硬盘认不到,关于Linux系统增加SCSI硬盘不识别的问题及解决办法
  14. 为什么量子计算机是锥形,科学家制作超高精度微腔为量子计算机铺垫
  15. Android中的传感器之---磁场传感器
  16. 什么是MVC开发模式?
  17. python中uuid用法详解
  18. Python http.server 服务器
  19. 新概念二册 Lesson 45 A clear conscience问心无愧(复习被动语态+过去完成时被动语态)
  20. JavaWeb 打开的默认主页设置问题

热门文章

  1. php输出绝对值,PHP实现找出有序数组中绝对值最小的数算法分析
  2. 【docker-gpu】报错:W: GPG error:xxx, InRelease: The following signatures couldn‘t be verified because th
  3. SQL查询语句可以执行,但是提示对象名无效
  4. 面试题:为什么说 Mybatis 是半自动ORM 映射工具?它与全自动的区别在哪里?
  5. 制药工程专业计算机考试考哪样,制药工程考研可以考什么专业
  6. org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not runn Hbase shell 无法执行命令
  7. 号外: 我开通了英语专栏
  8. 南京计算机工程大学分数线,2017南京信息工程大学录取分数线
  9. < abbr >标签 缩写
  10. shaderlab 中 use pass、grab pass的用法