Girl Love Value
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 743 Accepted Submission (s): 412
Problem Descriptionlove in college are a happy thing but always has so many pity boys or girls can not find it.
Now a chance are 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 are not a interesting thing to K boys. But know Kiki has a lot of friends which all is beautiful girl!!!!. Now you must being sure how wonderful things it was if you are choose by Kiki.
Problem is coming, n a boys want to go to travel with Kiki. But Kiki only choose K from them. Kiki every day would choose one single boy, so after K days the choosing would be end. Each boys has a love value (Li) to Kiki, and also has a other value (Bi), if one boy can is choose by Kiki he love Value would 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 is 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
Authoryifenfei sourcehdu Girls ' open--who says women are inferior to men
Test instructions: There are n boys chasing a girl, each boy has a corresponding love value VX (i), given a day m, this girl can only find a girl, and get this boy's love value. Every day, each boy's love value will reduce the corresponding vy (i), ask girls how to choose, M days later, can get the greatest love value. I look at a greedy topic, each time the first choice of the most admired, and this girl date. But later found that the problem, if the number of days, some boys fall in love value is very fast, so greedy is not good to deal with, because I do not know the value of the love of M-day, also do not realize that the first choice to reduce much or the value of love is big. It's actually a 01-pack variant. The discussion chose not to select the n-1 person. If selected, the value of Love is Dp[j]. If not chosen, the love value is dp[j-1]+ This boy's Love value-(The daily reduced love value * days). On the Code
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include < vector> #include <queue> #include <math.h>using namespace std;struct node{int value,ans;}; BOOL CMP (node A,node b) {return a.ans>b.ans;} /*---------------------------------------------*////The following comment section is a greedy error solution. /*---------------------------------------------*/int Main () {node f[1005]; int dp[1005]; int N,day,i,j,love,max; while (Cin>>n>>day) {memset (dp,0,sizeof (DP)); love=0; for (i=0; i<n; i++) cin>>f[i].value; for (i=0; i<n; i++) cin>>f[i].ans; Sort (f,f+n,cmp); /* while (day--) {love+=f[0].value; f[0].value=-100005; Break } for (i=0; i<n; i++) {if (f[i].value!=-100005) F[i].value-=f[i].ans ; } sort (f,f+n,cmp); } */for (i=0; i<n; i++) for (j=day; j>0; j--) {Dp[j]=max (dp[ j],dp[j-1]+f[i].value-f[i].ans* (j-1)); }//cout<<love<<endl; cout<<dp[day]<<endl; } return 0;}
HDU 2670 Girl Love Value