Submission
Status:
P-PPP-----
Score: 40
User: Jokul
Problemset: เทน้ำ
Language: c
Time: 0.001 second
Submitted On: 2025-04-25 09:18:53
#include <stdio.h>
int main() {
int n, l, x;
scanf("%d %d %d", &n, &l, &x);
int maxl = 2 * l; // Maximum length
int a[n + 1][maxl + 1];
// Initialize the array
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= maxl; j++) {
a[i][j] = 0;
}
}
// Base case: 1 way to be at position x with 0 moves
if (x <= maxl) {
a[0][x] = 1;
}
// Dynamic programming to fill the array
for (int i = 0; i < n; i++) {
for (int j = 0; j <= maxl; j++) {
if (a[i][j] > 0) {
// Move right
if (j + 1 <= maxl) {
a[i + 1][j + 1] += a[i][j];
}
// Move left
if (j - 1 >= 0) {
a[i + 1][j - 1] += a[i][j];
}
}
}
}
// Output the results based on the parity of n
for (int j = 0; j <= maxl; j++) {
if (n % 2 == 1) {
if (j % 2 == 0) {
printf("%d ", a[n][j]);
}
} else {
if (j % 2 == 1) {
printf("%d ", a[n][j]);
}
}
}
printf("\n"); // New line for better output formatting
return 0;
}