比赛 暑假培训B班二测 评测结果 AWTTTTTTTTT
题目名称 待售干草 最终得分 9
用户昵称 日光。 运行时间 9.001 s
代码语言 C++ 内存使用 0.30 MiB
提交时间 2012-07-22 10:41:00
显示代码纯文本
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int N,M;
  5. int a[5001]={0};
  6. int ans;
  7. int search(int temp,int step)
  8. {
  9. if(step==M)
  10. {
  11. if(ans<temp) ans=temp;
  12. }
  13. else
  14. {
  15. for(int i=step+1;i<=M;i++)
  16. {
  17. if(temp+a[i]<=N)
  18. {
  19. search(temp+a[i],step+1);
  20. break;
  21. }
  22. else
  23. {
  24. search(temp,step+1);
  25. }
  26. }
  27. }
  28. return ans;
  29. }
  30. int main()
  31. {
  32. ifstream fin("hay4sale.in");
  33. ofstream fout("hay4sale.out");
  34. fin>>N>>M;
  35. ans=0;
  36. for(int i=1;i<=M;i++) fin>>a[i];
  37. search(0,0);
  38. fout<<ans<<endl;
  39. return 0;
  40. }