Hdu 2512 (water question, DP)

Source: Internet
Author: User

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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.