zoukankan      html  css  js  c++  java
  • 【HDOJ】3466 Proud Merchants

    先排序预处理,后01背包。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 
     5 #define MAX(a, b) (a>b) ? a:b
     6 
     7 int dp[5000];
     8 
     9 typedef struct {
    10     int p, q, v;
    11 } stuff_st;
    12 
    13 stuff_st stuffs[505];
    14 
    15 int comp(const void *a, const void *b) {
    16     stuff_st *p = (stuff_st *)a;
    17     stuff_st *q = (stuff_st *)b;
    18 
    19     return (p->q-p->p) - (q->q-q->p);
    20 }
    21 
    22 int main() {
    23     int n, m;
    24     int i, j;
    25 
    26     while (scanf("%d %d", &n, &m) != EOF) {
    27         for (i=1; i<=n; ++i) {
    28             scanf("%d%d%d", &stuffs[i].p, &stuffs[i].q, &stuffs[i].v);
    29         }
    30         memset(dp, 0, sizeof(dp));
    31         qsort(stuffs+1, n, sizeof(stuff_st), comp);
    32         for (i=1; i<=n; ++i) {
    33             for (j=m; j>=stuffs[i].q; --j) {
    34                 dp[j] = MAX(dp[j], dp[j-stuffs[i].p]+stuffs[i].v);
    35             }
    36             /*
    37             for (j=0; j<=m; ++j) {
    38                 printf("%d ", dp[j]);
    39             }
    40             printf("
    ");
    41             */
    42         }
    43         printf("%d
    ", dp[m]);
    44     }
    45 
    46     return 0;
    47 }
  • 相关阅读:
    cf B. Sonya and Exhibition
    cf B. Sonya and Exhibition
    1000C
    1000C
    AOE网打印所有的关键路径
    AOE网打印所有的关键路径
    拓扑排序判断有向图是否成环
    拓扑排序判断有向图是否成环
    迭代器
    Dictionary Aizu
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3756586.html
Copyright © 2011-2022 走看看