• Source
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. int n, k;
    5. int arr[20];
    6. void read ()
    7. {
    8. cin>>n>>k;
    9. arr[0]=0;
    10. for (int i=1; i<=n; i++)
    11. {
    12. int tmp;
    13. cin>>tmp;
    14. arr[i]=arr[i-1]+tmp;
    15. }
    16. }
    17.  
    18. int count=0;
    19. int tim (int x, int bg, int ed, int K)
    20. {
    21. if (bg > ed) return 0;
    22. if (K==1)
    23. {
    24. if (x==arr[ed]-arr[bg-1])
    25. {
    26. count++;
    27. return 1;
    28. }
    29. else return 0;
    30. }
    31. else if (K==0) return 0;
    32. else
    33. {
    34. int BG = bg;
    35. for (int i=bg; i<=ed; i++)
    36. {
    37. if (arr[i]-arr[BG-1]==x)
    38. {
    39. tim (x, i+1, ed, K-1);
    40. }
    41. }
    42. }
    43. }
    44.  
    45. int main ()
    46. {
    47. read ();
    48. if (k==1)
    49. {
    50. count=1;
    51. }
    52. else
    53. {
    54. for (int i=1; i<=n; i++)
    55. {
    56. int label = arr[i];
    57. tim (label, i+1, n, k-1);
    58. }
    59. }
    60. cout<<count;
    61. return 0;
    62. }