zoukankan      html  css  js  c++  java
  • HDU 2639 Bone Collector II

    Bone Collector II

    Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1158    Accepted Submission(s): 566


    Problem Description
    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't matter,I will give you a link:

    Here is the link:http://acm.hdu.edu.cn/showproblem.php?pid=2602

    Today we are not desiring the maximum value of bones,but the K-th maximum value of the bones.NOTICE that,we considerate two ways that get the same value of bones are the same.That means,it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.

    If the total number of different values is less than K,just ouput 0.
     

    Input
    The first line contain a integer T , the number of cases.
    Followed by T cases , each case three lines , the first line contain two integer N , V, K(N <= 100 , V <= 1000 , K <= 30)representing the number of bones and the volume of his bag and the K we need. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
     

    Output
    One integer per line representing the K-th maximum of the total value (this number will be less than 231).
     

    Sample Input
    3
    5 10 2
    1 2 3 4 5
    5 4 3 2 1
    5 10 12
    1 2 3 4 5
    5 4 3 2 1
    5 10 16
    1 2 3 4 5
    5 4 3 2 1
     

    Sample Output
    12
    2
    0
     
    解题代码:
    View Code
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 using namespace std;
     5 
     6 #define Max 1010
     7 struct node
     8 {
     9     int s;
    10     int v;
    11 }boot[Max];
    12 int dp[Max][35];
    13 int A[35], B[35];
    14 
    15 int main()
    16 {
    17     int T;
    18     int N, V, d;
    19     int i, j;
    20     scanf ("%d", &T);
    21     while (T--)
    22     {
    23         memset(dp, 0, sizeof(dp));
    24         scanf ("%d%d%d", &N, &V, &d);
    25         for (i = 1; i <= N; i++)
    26             scanf ("%d", &boot[i].s);
    27         for (i = 1; i <= N; i++)
    28             scanf ("%d", &boot[i].v);
    29         for (i = 1; i <= N; i ++)
    30         {
    31             for (j = V; j >= boot[i].v; j--)
    32             {
    33                 for (int k = 1; k <= d; k ++)
    34                 {
    35                     A[k] = dp[j - boot[i].v][k] + boot[i].s;
    36                     B[k] = dp[j][k];
    37                 }
    38                 A[d+1] = B[d+1] = -1;
    39                 int a, b, c;
    40                 a = b = c = 1;
    41                 while (c <= d && (A[a] != -1 || B[b] != -1))
    42                 {
    43                     if (A[a] > B[b])
    44                     {
    45                         dp[j][c] = A[a];
    46                         a ++;
    47                     }
    48                     else
    49                     {
    50                         dp[j][c] = B[b];
    51                         b ++;
    52                     }
    53                     if (dp[j][c] != dp[j][c-1])
    54                         c ++;
    55                 }
    56             }
    57         }
    58         printf ("%d\n", dp[V][d]);
    59     }
    60 }
     
     
  • 相关阅读:
    C# Stream篇(—) -- Stream基类-----转载
    C# Stream篇(三) -- TextWriter 和 StreamWriter---转载
    C#文件过滤器filter---转载
    微信列表展示与详情页
    关于微信表单添加与图片上传
    登录的php代码 接口开发
    文章列表与点赞的一些功能实现 以及详情页点赞、取消赞操作
    Linux 简单命令总结
    微信小程序实现登录功能 (第一种模式)
    201509-1 数列分段 Java
  • 原文地址:https://www.cnblogs.com/shengshouzhaixing/p/3008980.html
Copyright © 2011-2022 走看看