记录编号 527028 评测结果 AAAAAAAAAA
题目名称 [NOIP 2006]开心的金明 最终得分 100
用户昵称 GravatarGo灬Fire 是否通过 通过
代码语言 C++ 运行时间 0.022 s
提交时间 2019-02-06 11:56:38 内存使用 3.56 MiB
显示代码纯文本
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. #define LL long long
  8. #define Inf 1e9
  9. const int maxn=35000;
  10. int W,n;
  11. int w[maxn],v[maxn];
  12. int f[maxn];
  13. void Init();
  14. int main(){
  15. freopen("happy.in","r",stdin);
  16. freopen("happy.out","w",stdout);
  17. Init();
  18. return 0;
  19. }
  20. void Init(){
  21. scanf("%d%d",&W,&n);
  22. for(int i=1;i<=n;i++){
  23. scanf("%d%d",&w[i],&v[i]);
  24. v[i]*=w[i];
  25. }
  26. for(int i=1;i<=n;i++){
  27. for(int j=W;j>=w[i];j--){
  28. f[j]=max(f[j],f[j-w[i]]+v[i]);
  29. }
  30. }
  31. printf("%d\n",f[W]);
  32. }
  33.  
  34.  
  35.