hdoj2670Girl Love Value【01背包】
2015-09-20 21:58
561 查看
Girl Love ValueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 769 Accepted Submission(s): 431 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 |
解题思路:01背包
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int maxn=1010; int MIM(int a,int b){ return a<b?a:b; } int MAX(int a,int b){ return a>b?a:b; } struct Node{ int l,b; }A[maxn]; bool cmp(Node a,Node b){ return a.b>b.b; } int dp[maxn]; int main() { int i,j,k,n; while(scanf("%d%d",&n,&k)!=EOF){ for(i=0;i<n;++i){ scanf("%d",&A[i].l); } for(i=0;i<n;++i){ scanf("%d",&A[i].b); } sort(A,A+n,cmp);//保证优先选择当前最大的 memset(dp,0,sizeof(dp)); for(i=0;i<n;++i){ for(j=k;j>=1;--j){ dp[j]=MAX(dp[j],dp[j-1]+A[i].l-A[i].b*(j-1)); } } printf("%d\n",dp[k]); } return 0; }
相关文章推荐
- 初学Java的备忘录
- Java线程模型缺陷
- Test love machine
- only love_ westlife
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VA
- 超级肉麻情话
- VS2008中VA解决QT不能自动补全问题及不识别类的问题
- I'm stay there waiting for you at corner
- Arrive the world
- VS2013中使用QT编程时visual assisent(VA)不能自动补全
- Lua游戏引擎Love试用
- Visual Studio + VA 常用快捷键
- Visual Assist X_ refactor功能初探[原]
- Visual Assist X_ va snippets功能简介
- 使用mean-shift方法、隐马尔科夫模型的恋爱指南
- VisualAssistX常用的快捷键
- 用VA快速添加注释+快捷键
- 程序员的爱情故事
- 戀愛迷霧
- oracle char nchar varchar varchar2 nvarchar2