洛谷 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\n",max(f[H][0], f[H][1]));
45     return 0;
46 }

 

posted @ 2017-11-09 15:57  third2333  阅读(181)  评论(0编辑  收藏  举报