The Mini version that has previously done this kind of question. The maximum n value is only 25. Although this question is 2000, it does not affect the method I used to cut it.
Repeat the previous explanation: There are only n groups of n cards, which are divided into one group, two groups, and three groups... N groups. The I card into the j group can have the first two cases come: I-1 card into the J-1 group, as long as the I card into a group of independent, or the I-1 card into the j group, which of the I card can be inserted at Will meets the conditions.
State transition equation: mark [I] [j] = mark [I-1] [J-1] + mark [I-1] [j] * j.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Define N 2005
Int mark [N] [N];
Int main ()
{
Int I, j;
Memset (mark, 0, sizeof (mark ));
For (I = 1; I <= 2000; I ++)
{
Mark [I] [1] = 1;
Mark [I] [0] = 0;
For (j = 1; j <= 2000; j ++)
{
If (I = j)
{
Mark [I] [j] = 1;
Continue;
}
Mark [I] [j] = mark [I-1] [J-1] + mark [I-1] [j] * j;
Mark [I] [j] %= 1000;
}
}
Int n, T;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
Int ans = 0;
For (I = 0; I <= n; I ++)
Ans + = mark [n] [I];
Printf ("% d \ n", ans % 1000 );
}
Return 0;
}
# Include <stdio. h>
# Include <string. h>
# Define N 2005
Int mark [N] [N];
Int main ()
{
Int I, j;
Memset (mark, 0, sizeof (mark ));
For (I = 1; I <= 2000; I ++)
{
Mark [I] [1] = 1;
Mark [I] [0] = 0;
For (j = 1; j <= 2000; j ++)
{
If (I = j)
{
Mark [I] [j] = 1;
Continue;
}
Mark [I] [j] = mark [I-1] [J-1] + mark [I-1] [j] * j;
Mark [I] [j] %= 1000;
}
}
Int n, T;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
Int ans = 0;
For (I = 0; I <= n; I ++)
Ans + = mark [n] [I];
Printf ("% d \ n", ans % 1000 );
}
Return 0;
}