首页 > 代码库 > hdu 2069 dfs

hdu 2069 dfs

  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6. __int64 flag;
  7. int num[] = {50, 25, 10, 5, 1};
  8. void dfs(int n, int deep, int last, int coin)
  9. {
  10. if(n<0 || coin>100 ) return;
  11. if(n==0 && coin <=100)
  12. {flag++; return;}
  13. for(int i=deep; i<5; i++)
  14. {
  15. if(num[i] <= last)
  16. {
  17. last = num[i];
  18. coin++;
  19. dfs(n-num[i], deep, last, coin);
  20. coin--;
  21. }
  22. }
  23. }
  24. int result[300];
  25. int main()
  26. {
  27. int n;
  28. //while( scanf("%d", &n)!=EOF)
  29. for(n=0; n<=250; n++)
  30. {
  31. flag = 0;
  32. //if(n==0) {printf("0\n"); continue;}
  33. if(n >= 50) dfs(n, 0, num[0], 0);
  34. else if(n>=25) dfs(n, 1, num[1], 0);
  35. else if(n>=10) dfs(n, 2, num[2], 0);
  36. else if(n>=5) dfs(n, 3, num[3], 0);
  37. else dfs(n,4, num[4], 0);
  38. printf("%I64d\n", flag);
  39. //result[n] = flag;
  40. }
  41. return 0;
  42. }



来自为知笔记(Wiz)


附件列表

     

    hdu 2069 dfs