码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ 题目2670 Girl Love Value(01背包)

时间:2015-06-27 10:04:18      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

Girl Love Value

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


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
 

Author
yifenfei
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2668 2675 2671 2673 2672 
 


题目大意:有n个男孩,每个男孩对那个女孩都有一个爱慕值li,一个递减值bi,当女孩不选他时他的爱慕之减去没选他的天数乘递减值,每天只能选一个男孩,问选m个获得最大的m值是多少

ac代码

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
struct s
{
	int li,bi;
}a[1010];
int dp[1010];
int cmp(const void *a,const void *b)
{
	return (*(struct s *)b).bi-(*(struct s *)a).bi;
}
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int i,j;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i].li);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i].bi);
		}
		qsort(a,n,sizeof(a[0]),cmp);
		memset(dp,0,sizeof(dp));
		for(i=0;i<n;i++)
		{
			for(j=m;j>=1;j--)
			{
				dp[j]=max(dp[j],dp[j-1]+a[i].li-(j-1)*a[i].bi);
			}
		}
		printf("%d\n",dp[m]);
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDOJ 题目2670 Girl Love Value(01背包)

标签:

原文地址:http://blog.csdn.net/yu_ch_sh/article/details/46652655

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!