1006 one card adventure

Source: Internet
Author: User

Description

Because I have been studying algorithms for a long time and have no time to consider my personal issues, most of the handsome guys in the Beijing airlines ACM/ICPC training team are single. One day, they negotiated a wonderful plan "One Card Adventure" in the data center ". This plan was first proposed by wash, whose content was to write his contact information on the back of the campus card, and then deliberately "lose" his card somewhere (such as a water room, TD, canteen, main m ......) They hope that they can see their "lost" cards and take the initiative to contact them, so they will have the opportunity to invite mm to dinner. They decided to put their cards in basically the same book, and then "lost" the book to every corner of the campus. Just as everyone applauded this wonderful plan, everyone thought of a problem. Obviously, if there is only one card, there is only one way, that is, to put it into a book. When there are two cards, there are two options: Put the two cards in a book, or separate them in different books. When there are three cards, they have five options: [a, B, c] [AB, C] [BC, a] [AC, B] [ABC 〗] so, wash, the organizer of this evil program, wants to know that if the ACM/ICPC training team contains N handsome guys (that is, N cards ), how many different methods should these cards be included in the book.
Input

Contains multiple groups of data. The first act is N, indicating that there are N groups of data in total. Each row in N rows contains x, indicating that there are X cards in total. (1 <= x <= 2000 ).
Output

For each group of test data, output a line: different number of methods, because this number may be very large, we only need to divide it by the remainder of 10000.
Example input 4
1
2
3
100 sample output

1
2
5
751

Solution:
This is a dynamic planning question.

F [I] [J] = f [I-1] [J] * j + F [I-1] [J-1]; f [I] [J] indicates how to put one card into J books. Obviously, you can find out the rule by filling out the table. One is to put the I card into the J book, and the other is to not put the I card into the J book. The final result is to add f [I] [J] (j <= the number of cards in one card). Because there are multiple groups of data input, you can create tables first and then accumulate them directly.
#include<stdio.h>int f[2001][2001];int n,t,s; int main(){       int i,j;       for(i=1;i<=2000;i++)       {              f[i][i]=1;              f[i][1]=1;       }       for(i=3;i<=2000;i++)              for(j=2;j<i;j++)              {                     f[i][j]=f[i-1][j]*j+f[i-1][j-1];                                        if(f[i][j]>10000)                            f[i][j]%=10000;              }              scanf("%d",&n);              for(i=1;i<=n;i++)              {                     scanf("%d",&t);                     s=0;                     for(j=1;j<=t;j++)                            s+=f[t][j];                     if(s>10000) s%=10000;                     printf("%d\n",s);              }              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.