[DP problem] girl love value (DP problem) hdu2670

Source: Internet
Author: User
Problem descriptionLove in college is a happy thing but always have so far 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 beauti Ful girl !!!!. Now you must be sure how wonderful things it is if you are 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. InputThe 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)

OutputOutput only one integer about the maximum total love value Kiki can get by choose K boys.

Sample Input

3 310 20 304 5 64 320 30 40 502 7 6 5
Sample output
47104
Resolution: Sort Bi values in ascending order and then perform DP. DP [I] [J] indicates the maximum value of J for the first I.
DP [I] [J] = max (DP [I-1] [J], DP [I-1] [J-1] + J select the value of I)
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct da  {   int li;   int bi;}da;da dd[1001];int dp[1001][1001];int cmp(const void *a,const void *b){   da * c=(da *)a;   da * d=(da *)b;   return d->bi-c->bi;}int main(){int i,j,n,k;  while (scanf("%d%d",&n,&k)!=EOF)  {  for(i=1;i<=n;i++)  scanf("%d",&dd[i].li);  for(i=1;i<=n;i++)  scanf("%d",&dd[i].bi);  qsort(dd+1,n,sizeof(dd[0]),cmp);  memset(dp,0,sizeof(dp));  for(i=1;i<=n;i++)  for(j=1;j<=i;j++)  {  if(i-1>=j) dp[i][j]=dp[i-1][j];  int temp=dp[i-1][j-1]-dd[i].bi*(j-1)+dd[i].li;  if(i-1>=j-1&&temp>dp[i][j])  dp[i][j]=temp;  }  printf("%d/n",dp[n][k]);  }}/*3 310 20 304 5 64 320 30 40 502 7 6 5*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.