hdu 3732

    技术2022-05-18  14

     

    Ahui Writes Word

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 257    Accepted Submission(s): 115Problem DescriptionWe 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. InputThe 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) OutputOutput 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)”

     AuthorAhui SourceACMDIY第二届群赛 Recommendnotonlysuccess

     

    分析:明明就是贪心嘛。。。怎么错了??原来是多组读入,晕,wrong了n次

    #include<stdio.h> #include <algorithm> using namespace std; const int maxn=100010; struct data { int v,c; }g[maxn]; int f[20]; inline int max(int a,int b) { return a>b?a:b; } inline void get(int& a) { char ch=getchar(); while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar(); for (a=0; ch>='0'&&ch<='9'; ch=getchar()) a=a*10+ch-48; } inline bool cmp(data a,data b) { return a.v*b.c>b.v*a.c; } int main(int argc, char* argv[]) { int i,j,n,c,ans; while(scanf("%d%d",&n,&c)!=EOF) { for(i=0;i<n;++i)get(g[i].v),get(g[i].c); sort(g,g+n,cmp); ans=i=0,c-=10; while(i<n&&g[i].c<=c) { c-=g[i].c; ans+=g[i].v; ++i; } c+=10; for(j=0;j<=c;++j)f[j]=0; for(;i<n;++i) for(j=c;j>=g[i].c;--j) f[j]=max(f[j],f[j-g[i].c]+g[i].v); printf("%d/n",ans+f[c]); } return 0; }  

     


    最新回复(0)