fork download
  1. template<int N, int P>
  2. struct CountSumOfPoints {
  3. constexpr static const long long value = CountSumOfPoints<N - 1, P - 1>::value
  4. + CountSumOfPoints<N - 1, P - 2>::value
  5. + CountSumOfPoints<N - 1, P - 3>::value
  6. + CountSumOfPoints<N - 1, P - 4>::value
  7. + CountSumOfPoints<N - 1, P - 5>::value
  8. + CountSumOfPoints<N - 1, P - 6>::value;
  9. };
  10.  
  11. template<int P>
  12. struct CountSumOfPoints<1, P> {
  13. constexpr static const long long value = 0;
  14. };
  15.  
  16. template<>
  17. struct CountSumOfPoints<1, 1> {
  18. constexpr static const long long value = 1;
  19. };
  20.  
  21. template<>
  22. struct CountSumOfPoints<1, 2> {
  23. constexpr static const long long value = 1;
  24. };
  25.  
  26. template<>
  27. struct CountSumOfPoints<1, 3> {
  28. constexpr static const long long value = 1;
  29. };
  30.  
  31. template<>
  32. struct CountSumOfPoints<1, 4> {
  33. constexpr static const long long value = 1;
  34. };
  35.  
  36. template<>
  37. struct CountSumOfPoints<1, 5> {
  38. constexpr static const long long value = 1;
  39. };
  40.  
  41. template<>
  42. struct CountSumOfPoints<1, 6> {
  43. constexpr static const long long value = 1;
  44. };
  45.  
  46. template<int...>
  47. struct Indices {
  48. };
  49.  
  50. template<class Front, int BACK> struct Append;
  51.  
  52. template<int... FRONT, int BACK>
  53. struct Append<Indices<FRONT...>, BACK> {
  54. typedef Indices<FRONT..., BACK> type;
  55. };
  56.  
  57. template<int BEGIN, int END>
  58. struct IndexGenerator {
  59. typedef typename Append<typename IndexGenerator<BEGIN, END - 1>::type, END>::type type;
  60. };
  61.  
  62. template<int BEGIN>
  63. struct IndexGenerator<BEGIN, BEGIN> {
  64. typedef Indices<BEGIN> type;
  65. };
  66.  
  67. template<int N>
  68. struct IndexList {
  69. typedef typename IndexGenerator<N, 6 * N>::type type;
  70. };
  71.  
  72. template<int N, class Indices> struct Values;
  73.  
  74. template<int N, int... P>
  75. class Values<N, Indices<P...>> {
  76. public:
  77. static long long value(int n) {
  78. return values[n - N];
  79. }
  80.  
  81. private:
  82. static const long long values[sizeof...(P)];
  83. };
  84.  
  85. template<int N, int... P>
  86. const long long Values<N, Indices<P...>>::values[sizeof...(P)] = {
  87. CountSumOfPoints<N, P>::value...
  88. };
  89.  
  90. template<int N>
  91. using CountSumOfPointsTable = Values<N, typename IndexList<N>::type>;
  92.  
  93. #include <iostream>
  94.  
  95. int main() {
  96. //std::cout << CountSumOfPoints<20, 40>::value << std::endl;
  97. //std::cout << CountSumOfPointsTable<20>::value(40) << std::endl;
  98. for (int i = 20; i <= 120; ++i) {
  99. std::cout << CountSumOfPointsTable<20>::value(i) << std::endl;
  100. }
  101. return 0;
  102. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1
20
210
1540
8855
42504
177080
657400
2215875
6876100
19852910
53777220
137578715
334221400
774447600
1718122120
3661011200
7513026360
14883869260
28522751000
52968655260
95473613400
167259698400
285156111240
473630804445
767177392956
1212940768770
1873365928060
2828541558365
4177796844360
6040016957080
8552094731000
11864959484010
16136741780240
21522858933280
28163138907504
36166519159030
45594319698440
56443534859400
68631941843000
81987009993775
96240548343540
111030711156790
125912390300660
140376201624375
153875306132440
165858316337600
175805662952520
183266172913710
187890345960720
189456975899496
187890345960720
183266172913710
175805662952520
165858316337600
153875306132440
140376201624375
125912390300660
111030711156790
96240548343540
81987009993775
68631941843000
56443534859400
45594319698440
36166519159030
28163138907504
21522858933280
16136741780240
11864959484010
8552094731000
6040016957080
4177796844360
2828541558365
1873365928060
1212940768770
767177392956
473630804445
285156111240
167259698400
95473613400
52968655260
28522751000
14883869260
7513026360
3661011200
1718122120
774447600
334221400
137578715
53777220
19852910
6876100
2215875
657400
177080
42504
8855
1540
210
20
1