洛谷P1659 养猪

洛谷P1659 养猪 

 

 1 #include <bits/stdc++.h> 
 2 #define For(i,j,k) for(int i=j;i<=k;i++) 
 3 using namespace std ; 
 4 
 5 const int N = 1011 ; 
 6 int n,day ; 
 7 int f[N] ; 
 8 struct node{
 9     int p,a ; 
10 }t[N];
11 inline int read() 
12 {
13     int x = 0 , f = 1 ; 
14     char ch = getchar() ; 
15     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
16     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
17     return x * f ;  
18 }
19 
20 inline bool cmp(node a,node b) {
21     if(a.p!=b.p) return a.p > b.p ; 
22     return a.a > b.a ; 
23 }
24 
25 int main()
26 {
27     n = read() ; day = read() ; 
28     For(i,1,n) t[i].a=read() ; 
29     For(i,1,n) t[i].p=read() ; 
30     sort(t+1,t+n+1,cmp) ; 
31     For(i,1,n) 
32       for(int j=max(i,day);j>=1;j--) 
33         f[j] = max(f[j],f[j-1]+max(0,t[i].a-t[i].p*(j-1)) ) ; 
34     int ans = -100 ; 
35     For(i,1,day) ans = max(f[i],ans) ;      
36     //  为什么最后还要再扫一遍,是因为有可能中间几个体重已经减没了,
37     //  然后体重为0的猪也被当成了一头猪在计算 
38     printf("%d\n",ans) ; 
39     return 0 ; 
40 }

 

转载于:https://www.cnblogs.com/third2333/p/7551404.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值