zoukankan      html  css  js  c++  java
  • E

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<vector>
     5 using namespace std;
     6 const int N=110,M=1e4+10,K=15;
     7 int f[N][M],n,m,k;
     8 struct node
     9 {
    10     int cost,val;
    11     node(){}
    12     node(int a,int b):cost(a),val(b){}
    13 };
    14 vector<node>a[K];
    15 
    16 int main()
    17 {
    18     freopen("1.in","r",stdin);
    19     freopen("1.out","w",stdout);
    20     while (~scanf("%d%d%d",&n,&m,&k)) {
    21         for (int i=1;i<=k;i++) a[i].clear();
    22         for (int i=0;i<n;i++) {
    23             int id,b,c;
    24             scanf("%d%d%d",&id,&b,&c);
    25             a[id].push_back(node(b,c));
    26         }
    27         memset(f,-1,sizeof(f));
    28         f[0][0]=0;
    29         for (int i=1;i<=k;i++) {
    30             for (int j=0;j<a[i].size();j++) {
    31                 int c=a[i][j].cost,v=a[i][j].val;
    32                 for (int w=m;w>=c;w--) {
    33                     if (f[i][w-c]>-1) {
    34                         f[i][w]=max(f[i][w],f[i][w-c]+v);
    35                     }
    36                     if (f[i-1][w-c]>-1) {
    37                         f[i][w]=max(f[i][w],f[i-1][w-c]+v);
    38                     }
    39                 }
    40             }
    41         }
    42         int t=-1;
    43         for (int i=0;i<=m;i++) t=max(t,f[k][i]);
    44         if (t>-1) printf("%d ",t);
    45         else printf("Kid is sad. ");
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    最短路--floyd算法模板
    poj2367 拓扑序
    poj1094 拓扑序
    hdu3231 拓扑序
    hdu1811 并查集+拓扑序
    hdu3342 拓扑序
    hdu2647 拓扑序
    hdu1285 拓扑序
    UVA10305 拓扑序
    $.proxy
  • 原文地址:https://www.cnblogs.com/acvc/p/4419852.html
Copyright © 2011-2022 走看看