zoukankan      html  css  js  c++  java
  • bzoj2021[Usaco2010 Jan]Cheese Towers*

    bzoj2021[Usaco2010 Jan]Cheese Towers

    题意:

    John要建一个奶酪塔,高度最大为T。他有N种奶酪,每种无限个,第i种高度为Hi(一定是5的倍数),价值为Vi。一块高度>=K的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(多块只算一次),它的高度就会变成原来的4/5。求最大价值。n≤100,t≤1000

    题解:

    可以枚举放哪个≥k的奶酪放在顶,其它奶酪高度变为4/5,做个完全背包。最后再算一个没有≥k的奶酪放在顶的最大价值,比较一下。注意被放在顶的奶酪可以再选,因为是每种奶酪无限个。

    代码:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define inc(i,j,k) for(int i=j;i<=k;i++)
     5 #define maxn 110
     6 #define INF 0x3fffffff
     7 using namespace std;
     8 
     9 struct nd{int h,v;}nds[maxn];
    10 int f[2][maxn*10],n,t,k,x,y,ans;
    11 inline int read(){
    12     char ch=getchar(); int f=1,x=0;
    13     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
    14     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    15     return f*x;
    16 }
    17 int main(){
    18     n=read(); t=read(); k=read(); inc(i,1,n)nds[i].v=read(),nds[i].h=read();
    19     inc(i,1,n)if(nds[i].h>=k&&t>=nds[i].h){
    20         x=0; y=1; memset(f,0,sizeof(f)); t-=nds[i].h;
    21         for(int j=n;j>=1;j--){
    22             for(int l=t;l>=0;l--){
    23                 if(l+nds[j].h/5*4>t)f[y][l]=f[x][l];else f[y][l]=max(f[y][l+nds[j].h/5*4]+nds[j].v,f[x][l]);
    24             }
    25             swap(x,y);
    26         }
    27         ans=max(ans,f[x][0]+nds[i].v); t+=nds[i].h;
    28     }
    29     x=0; y=1; memset(f,0,sizeof(f));
    30     for(int i=n;i>=1;i--)if(nds[i].h<k){
    31         f[y][t]=0;
    32         for(int j=t;j>=0;j--){
    33             if(j+nds[i].h>t)f[y][j]=f[x][j];else f[y][j]=max(f[y][j+nds[i].h]+nds[i].v,f[x][j]);
    34         }
    35         swap(x,y);
    36     }
    37     ans=max(ans,f[x][0]); printf("%d",ans); return 0;
    38     return 0;
    39 }

    20160828

  • 相关阅读:
    POJ1201 Intervals & TYVJ 1589 西瓜种植 差分约束
    洛谷 P3385 【模板】负环 SPFA
    Test 2018-07-19 二中集训
    《一出好戏》一中高三学子誓师大会后记
    [NOI2012] 迷失游乐园 概率 期望 基环树DP
    codeforces CF983E NN country 树上倍增
    「Luogu P3521 [POI2011]ROT-Tree Rotations」
    「高等数学学习笔记 DAY18」
    「高等数学学习笔记 DAY17」
    「高等数学学习笔记 DAY16」
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5838013.html
Copyright © 2011-2022 走看看