您的位置:首页 > 产品设计 > UI/UE

HDU 3732 Ahui Writes Word

2011-07-25 14:34 267 查看
  

  

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


[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 ;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: