zoukankan      html  css  js  c++  java
  • 洛谷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
    ",ans) ; 
    39     return 0 ; 
    40 }
  • 相关阅读:
    POJ
    Fence Repair POJ
    COGS 2096. 不平凡的许愿树
    COGS 2095. 不平凡的引线
    BZOJ 4392 卡牌游戏
    COGS 2089. 平凡的测试数据
    Slim Span (最小生成树)
    【BZOJ1294】[SCOI2009]围豆豆Bean 射线法+状压DP+SPFA
    排列perm HYSBZ
    I
  • 原文地址:https://www.cnblogs.com/third2333/p/7551404.html
Copyright © 2011-2022 走看看