记录编号 419943 评测结果 AAAAAAAAAA
题目名称 [NOIP 2006]金明的预算方案 最终得分 100
用户昵称 GravatarFisher. 是否通过 通过
代码语言 C++ 运行时间 0.013 s
提交时间 2017-07-03 17:26:12 内存使用 1.60 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6. const int maxn=32010;
  7. const int maxm=70;
  8. int n,m;
  9. int f[maxn];
  10. struct bao{
  11. int w[5],c[5];
  12. int tot;//附件个数
  13. };
  14. bao wupin[maxn];
  15. int tot;
  16. int mk[maxm];
  17. int main(){
  18. freopen("budget.in","r",stdin);
  19. freopen("budget.out","w",stdout);
  20. scanf("%d%d",&n,&m);
  21. for(int i=1;i<=m;i++){
  22. int v,p,q;
  23. scanf("%d%d%d",&v,&p,&q);
  24. if(q==0){
  25. ++tot;
  26. mk[i]=tot;
  27. for(int j=1;j<=4;j++){
  28. wupin[tot].w[j]+=v;
  29. }
  30. for(int j=1;j<=4;j++){
  31. wupin[tot].c[j]+=v*p;
  32. }
  33. }
  34. else{
  35. wupin[mk[q]].tot++;
  36. wupin[mk[q]].w[wupin[mk[q]].tot+1]+=v;
  37. wupin[mk[q]].c[wupin[mk[q]].tot+1]+=v*p;
  38. wupin[mk[q]].w[4]+=v;
  39. wupin[mk[q]].c[4]+=v*p;
  40. if(wupin[mk[q]].tot==2)wupin[mk[q]].tot++;
  41. }
  42. }
  43. for(int k=1;k<=tot;k++){
  44. for(int v=n;v>=0;v--){
  45. for(int i=1;i<=wupin[k].tot+1;i++){
  46. if(v-wupin[k].w[i]>=0)f[v]=max(f[v],f[v-wupin[k].w[i]]+wupin[k].c[i]);
  47. }
  48. }
  49. }
  50. printf("%d\n",f[n]);
  51. return 0;
  52. }