HDU 25,121 cartoon Big Adventure (DP)

Source: Internet
Author: User

The Big Adventure of a cartoon

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2137 Accepted Submission (s): 1430


Problem description Because of long-term research algorithms, no time to take into account personal problems, BUAA ACM/ICPC Training Group of handsome buddies are mostly single. One day, they were in the computer room to discuss a wonderful plan "a cartoon Big Adventure". The plan was first proposed by WF, the plan is to write their own contact information on the back of the campus card, and then deliberately "lost" their cards in somewhere (such as water room, TD, canteen, main m ...). They want to have a mm to see their lost cards, can take the initiative to contact them, so that there is a chance to ask mm to eat. They decided to put their cartoons in the same book, and then lost them to every corner of the campus. When everyone applauded for this wonderful plan, we thought of a problem. Obviously, if there is only one card, then there is only one way, that is, to clip it into a book. When there are two cards, there are two options, that is, to clip two cards in a book, or separate in different books. When there are three cards, they have 5 options, namely:
{{A},{b},{c}}, {{a,b},{c}}, {{b,c},{a}}, {{a,c},{b}}, {{a,b,c}}
The organizer of this evil plan WF wants to know how many different ways to clip these cartoons into a book if the ACM training pair has n dudes (that is, n-cards).

Input contains multiple sets of data, the first behavior n, which indicates that there are next n sets of data. Each of the following lines is a number x, representing a total of X-cards. (1≤x≤2000).

Output one line for each set of data: the number of different methods, because this number can be very large, we just need to divide it by the remainder of 1000.

Sample Input4123100

Sample Output125751

AUTHORBUAA Campus 2007

DP[I][J] Represents the first I-card, divided into J-group method number.

When a new card is added, you can choose to put this card alone then there are dp[i-1][j-1] methods. You can also choose to insert this card into the original group, that is, the first i-1 number is divided into the J group and then the first card inserted. There are dp[i-1][j]*j ways.

/************************************************author:guanjuncreated TIME:2016/6/12 20:31:58File Name: hdu2512.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 1000#defineINF 0x3f3f3f3f#defineMAXN 10000#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) {    returnA>b;}intdp[ .][ .];intN;intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);    intT; CIN>>T;  while(t--) {scanf ("%d",&N);        CLE (DP); dp[0][0]=1;  for(intI=1; i<=n;i++){             for(intj=1; j<=i;j++) {Dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*J; DP[I][J]%=MoD; }        }        intans=0;  for(intI=1; i<=n;i++) ans+=Dp[n][i]; cout<<ans%mod<<Endl; }    return 0;}

HDU 25,121 cartoon Big Adventure (DP)

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.