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
  • 相关阅读:
    【C++基础】重载,覆盖,隐藏
    【Lintcode】003.Digit Counts
    【C++ Primer 5th】Chapter 15
    【Lintcode】120.Word Ladder
    牛客网上的题
    二叉树中和为某个值得路径
    数据库
    二叉搜索树的后序遍历序列
    从上往下打印二叉树
    二叉树的镜像
  • 原文地址:https://www.cnblogs.com/acvc/p/4419852.html
Copyright © 2011-2022 走看看