zoukankan      html  css  js  c++  java
  • 洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers

    洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers
    分两种状态 一种最上面有大奶酪
    一种没有

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cmath>
     4 #include <cstring>
     5 #include <string>
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iomanip>
     9 #define For(i,j,k) for(int i=j;i<=k;i++)
    10 #define Dow(i,j,k) for(int i=j;i>=k;i--)
    11 #define LL long long
    12 using namespace std ;
    13 inline int read() {
    14     int x = 0 , f = 1 ;
    15     char ch = getchar() ;
    16     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
    17     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
    18     return x * f ;
    19 }
    20 
    21 const int N = 1011, inf = 1e9;
    22 int n,H,K,ans,tot;
    23 int f[N][2];
    24 struct node{
    25     int h,v;
    26 }a[111];
    27 inline bool cmp_1(node a, node b) { return a.h > b.h; } 
    28 inline bool cmp_2(node a, node b) { return a.h < b.h; } 
    29 
    30 int main() {
    31     n=read(); H=read(); K=read();
    32     For(i, 1, n) a[i].v=read(), a[i].h = read();
    33     For(i, 1, H) f[i][1]=-1;
    34     sort(a+1, a+n+1, cmp_1); 
    35     for(; a[tot+1].h >= K; tot++) 
    36     sort(a+1, a+tot+1, cmp_2);  
    37     
    38     For(i, 1, n) 
    39       For(j, a[i].h, H) {
    40         f[j][0] = max(f[j][0], f[j-a[i].h][0]+a[i].v);
    41         if(f[j-a[i].h/5*4][1]!=-1) f[j][1] = max(f[j][1], f[j-a[i].h/5*4][1]+a[i].v);
    42         if(a[i].h>=K) f[j][1] = max(f[j][1], f[(j-a[i].h)/5*4][0]+a[i].v );
    43     }
    44     printf("%d
    ",max(f[H][0], f[H][1]));
    45     return 0;
    46 }
  • 相关阅读:
    跟着太白老师学python 10day 函数的动态参数 *args, **kwargs, 形参的位置顺序
    IO 流之字符流的缓冲区
    Java IO异常处理方式
    Java IO 流
    Java 其他对象的 API
    Java 集合框架之 JDK 1.5 新特性
    Java 集合框架工具类
    Java 集合框架之 Map
    Java 集合框架查阅技巧
    Java 集合框架之泛型
  • 原文地址:https://www.cnblogs.com/third2333/p/7809822.html
Copyright © 2011-2022 走看看