OFFSET
1,2
COMMENTS
Apparently a(n) = sum(k=0..n, C(k, n-k)*C(2*n-k, n) ). - Paul Barry, Dec 02 2008
REFERENCES
Romanian Informatics Olympiad, 2001
EXAMPLE
The valid sequences for n = 3 are (1, 1, 2), (1, 1, 3), (1, 2, 2), (1, 2, 3), (1, 3, 2), (1, 3, 3), (2, 1, 3), (2, 2, 3), (2, 3, 3).
PROG
(C)
#include <stdio.h>
#define MAX_N 1001
int N;
int DP[MAX_N][MAX_N], X[MAX_N][MAX_N];
int main() {
int i, j;
scanf("%d ", &N);
for(i = 1; i <= N; i++) { DP[1][i] = i; DP[2][i] = i * i; }
for(i = 3; i <= N; i++) {
for(j = 1; j <= N; j++) {
if(j - 2 >= 0) X[i][j] = X[i][j - 1] + DP[i - 2][j - 2];
DP[i][j] = DP[i][j - 1] + DP[i - 1][j - 1]
+ DP[i - 2][j - 1] + X[i][j];
}
}
printf("%d ", DP[N][N]);
return 0;
}
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Shravas Rao, Jul 30 2008
STATUS
approved