比赛 叫图论的DP题 评测结果 AAAAAAAAAAA
题目名称 Bessie 的体重问题 最终得分 100
用户昵称 Hyoi_iostream 运行时间 0.003 s
代码语言 C++ 内存使用 0.09 MiB
提交时间 2017-08-29 20:26:46
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. using namespace std;
  5. int weight,N;
  6. int a[505],f[45005];
  7. int Main(){
  8. freopen("diet.in","r",stdin);
  9. freopen("diet.out","w",stdout);
  10. scanf("%d%d",&weight,&N);
  11. for(int i=1;i<=N;i++) scanf("%d",&a[i]);
  12. for(int i=1;i<=N;i++)
  13. for(int j=weight;j>=a[i];j--){
  14. int temp=f[j-a[i]]+a[i];
  15. if(temp>f[j]) f[j]=temp;
  16. }
  17. printf("%d",f[weight]);
  18. // fclose(stdin);
  19. // fclose(stdout);
  20. return 0;
  21. }
  22. int work=Main();
  23. int main(){;
  24. }