hdu_2670Girl Love Value(dp)

Posted 有一天我们渺小的作为 或许 会巨大震动整个世界

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu_2670Girl Love Value(dp)相关的知识,希望对你有一定的参考价值。

题目链接: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 }

 

 

以上是关于hdu_2670Girl Love Value(dp)的主要内容,如果未能解决你的问题,请参考以下文章

HDU5663 Hillan and the girl

oc如何提取文件中的第n行第n个字符 比如: hello, boy, girl, i love

hdu 4324 Triangle LOVE 拓扑排序

# DZY Love Math 系列

HDU - 4422-The Little Girl who Picks Mushrooms

HDU 4324 Triangle LOVE(拓扑排序判环)