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 }

  

posted @ 2011-07-25 14:34  贺佐安  阅读(656)  评论(0编辑  收藏  举报