It can be solved by brute-force recursion. It should not be TLE, but we should consider memory optimization.
If f (I, j) is set, it indicates the number of solutions when I is set to J.
F (I, j) = f (1, J-1) + F (2, J-1) + ...... + F (I-1, J-1) (4> = j> = 1), recursively solving from F (n, 4.
However, since there are only N * 4 statuses at most, you can simply remember them.
Initialization: f (I, 1) = 1 (1 <= I <= n-3)
1 # include <cstdio> 2 using namespace STD; 3 int N; 4 long memory [5] [1, 101]; 5 long F (INT cur, int now) 6 {7 if (now = 0 | cur <now) return 0; 8 If (memory [now] [cur]) return memory [now] [cur]; 9 long res = 0; 10 for (INT I = 1; I <cur; I ++) RES + = f (I, now-1 ); 11 return memory [now] [cur] = res; 12} 13 int main () 14 {15 scanf ("% d", & N ); 16 For (INT I = 1; I <= n-3; I ++) memory [1] [I] = 1; 17 printf ("% LLD \ n ", F (n, 4); 18 return 0; 19}
[Dynamic Planning] [memory-based search] [Search] codevs 1262 don't pass the ball to my 2012 CCC Canadian high school student informatics ausai