• HDU 3732 Ahui Writes Word


      

      

    Ahui Writes Word

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 434 Accepted Submission(s): 182


    Problem Description

    We all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length of each word does not exceed 10 by only lowercase letters), Ahui wrote the complexity of the total is less than or equal to C.
    Question: the maximum value Ahui can get.
    Note: input words will not be the same.

    Input

    The first line of each test case are two integer N , C, representing the number of Ahui’s words and the total complexity of written words. (1 ≤ N ≤ 100000, 1 ≤ C ≤ 10000)
    Each of the next N line are a string and two integer, representing the word, the value(Vi ) and the complexity(Ci ). (0 ≤ Vi , Ci ≤ 10)

    Output

    Output the maximum value in a single line for each test case.

    Sample Input

    5 20 go 5 8 think 3 7 big 7 4 read 2 6 write 3 5

    Sample Output

    15
    Hint
    Input data is huge,please use “scanf(“%s”,s)”

    Author

    Ahui

    Source

    Recommend

    notonlysuccess
     
     1 #include<stdio.h>
    2 #include<string.h>
    3 char ch[100] ;
    4 int nkind , total_comp ;
    5 int value[100024] , comp[100024] , fine[100024] , map[11][11];
    6 int main ()
    7 {
    8 int pos , x , y ,sum , t ;
    9 while ( scanf ( "%d%d" , &nkind , &total_comp ) != EOF )
    10 {
    11 memset( map , 0 , sizeof (map) ) ;
    12 for ( int i = 0 ; i < nkind ; i ++ )
    13 {
    14 scanf ( "%s%d%d" , ch , &x , &y ) ;
    15 map[x][y] ++ ;
    16 }
    17 pos = 0 ; // 用二分制转换成01背包
    18 for ( int i = 0 ; i <= 10 ; i ++ )
    19 for ( int j = 0 ; j <= 10 ; j ++ )
    20 {
    21 if( map[i][j] >= 1 )
    22 {
    23 sum = 1 , t = 1 ;
    24 while ( sum <= map[i][j] )
    25 {
    26 value[pos] = i * t ;
    27 comp[pos++] = j * t ;
    28 t *= 2 ;
    29 sum += t ;
    30 }
    31 if ( ( sum - t ) < map[i][j] )
    32 {
    33 value[pos] = i * (map[i][j]-sum + t) ;
    34 comp[pos++] = j * (map[i][j]-sum + t) ;
    35 }
    36 }
    37 }
    38 memset( fine , 0 , sizeof (fine) ) ;
    39 for ( int i = 0 ; i < pos ; i ++ )
    40 for ( int j = total_comp ; j >= comp[i] ; -- j )
    41 if ( fine[j] < fine[j-comp[i]] + value[i] )
    42 fine[j] = fine[j-comp[i]] + value[i] ;
    43 printf ( "%d\n" , fine[total_comp] ) ;
    44 }
    45 return 0 ;
    46 }

      

  • 相关阅读:
    Codeforces 1093D(染色+组合数学)
    Codeforces 1093C (思维+贪心)
    Codeforces 1082D (贪心)
    Codeforces 433A (背包)
    BZOJ 3262(Treap+树状数组)
    BZOJ 1588 (treap)
    Codeforces 1061C (DP+滚动数组)
    Codeforces 1080C 题解(思维+二维前缀和)
    周记 2015.07.12
    周记 2015.07.04
  • 原文地址:https://www.cnblogs.com/jbelial/p/2116160.html
Copyright © 2020-2023  润新知