HDU 3732 Ahui Writes Word
2011-07-25 14:34
267 查看
Ahui Writes Word
TimeLimit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 434 Accepted Submission(s):
182
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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)
[align=left]Output[/align]
Output the maximum value in a single line for each test
case.
[align=left]Sample Input[/align]
5 20
go 5 8
think 3 7
big 7 4
read 2 6
write 3 5
[align=left]Sample Output[/align]
15
Hint
Input data is huge,please use “scanf(“%s”,s)”
[/i]
[align=left]Author[/align]
Ahui
[align=left]Source[/align]
ACMDIY第二届群赛
[align=left]Recommend[/align]
notonlysuccess
#include<stdio.h> #include<string.h> char ch[100] ; int nkind , total_comp ; int value[100024] , comp[100024] , fine[100024] , map[11][11]; int main () { int pos , x , y ,sum , t ; while ( scanf ( "%d%d" , &nkind , &total_comp ) != EOF ) { memset( map , 0 , sizeof (map) ) ; for ( int i = 0 ; i < nkind ; i ++ ) { scanf ( "%s%d%d" , ch , &x , &y ) ; map[x][y] ++ ; } pos = 0 ; // 用二分制转换成01背包 for ( int i = 0 ; i <= 10 ; i ++ ) for ( int j = 0 ; j <= 10 ; j ++ ) { if( map[i][j] >= 1 ) { sum = 1 , t = 1 ; while ( sum <= map[i][j] ) { value[pos] = i * t ; comp[pos++] = j * t ; t *= 2 ; sum += t ; } if ( ( sum - t ) < map[i][j] ) { value[pos] = i * (map[i][j]-sum + t) ; comp[pos++] = j * (map[i][j]-sum + t) ; } } } memset( fine , 0 , sizeof (fine) ) ; for ( int i = 0 ; i < pos ; i ++ ) for ( int j = total_comp ; j >= comp[i] ; -- j ) if ( fine[j] < fine[j-comp[i]] + value[i] ) fine[j] = fine[j-comp[i]] + value[i] ; printf ( "%d\n" , fine[total_comp] ) ; } return 0 ; }
相关文章推荐
- hdu 3732 Ahui Writes Word
- hdu 3732 Ahui Writes Word
- hdu 3732 Ahui Writes Word(多重背包)
- HDU 3732 Ahui Writes Word
- HDU 3732 Ahui Writes Word(多重背包)
- hdu 3732 Ahui Writes Word
- HDU 3732 Ahui Writes Word(多重背包)
- hdu 3732 Ahui Writes Word
- HDU - 3732 Ahui Writes Word(多重背包)
- HDU 3732 Ahui Writes Word
- HDU 3732 Ahui Writes Word(多重背包问题)
- HDU 3732 Ahui Writes Word
- hdu 3732 Ahui Writes Word 多重背包 小心超时
- HDU 3732 Ahui Writes Word(01背包转化为多重背包)
- hdu 3732 Ahui Writes Word(多重背包的二进制思想优化)
- HDU ACM Steps 3.3.3 Ahui Writes Word || HDU 3732 Ahui Writes Word
- HDU 3732 Ahui Writes Word
- hdu 3732 Ahui Writes Word 【多重背包】、好题
- hdu 3732 Ahui Writes Word(简单dp+贪心)
- HDU 3732 Ahui Writes Word 解题报告