Zstu Learning algorithm 020--dp--queuing to buy tickets

Source: Internet
Author: User

Description a regular game before the start of the ticket work is underway. Each ticket is 50 yuan, the existing K (1 <= k <= 30) People queue to buy tickets, of which n people holding 50 yuan of money, the remaining m people holding 100 yuan of money, assuming the beginning of the ticket office without money, To find out the ticket office does not have the number of different queuing species (the same denomination of the same value of the person in the same queue) input multiple sets of test data, first enter the integer t to represent the number of groups, then each group entered 2 integers n and moutput for each group of test data output 1 rows, Value is the number of queued species in the title description, sample Input
21 21 1
Sample Output
01
HINT The main idea: DP is to see the relationship between the two states do not look at the whole, so dp[i][j] = Dp[i-1][j] is certainly satisfied, if the number of n is greater than or equal to M, the current can find the open, dp[i][j] + = dp[i][j-1];
#include <cstdio>#include<cstring>using namespacestd;intMain () {intT; scanf ("%d",&T);  while(t--){        intdp[ -][ -]; Memset (DP,0,sizeof(DP)); intn,m; scanf ("%d%d",&n,&m); if(N <m) {printf ("0\n"); Continue; }         for(inti =0; I <= N; i++){             for(intj =0; J <= M; J + +){                if(i = =0) Dp[i][j] =0; Else if(J = =0&& I! =0) Dp[i][j] =1; Else{Dp[i][j]= dp[i-1][j]; if(i >= J) dp[i][j] + = dp[i][j-1]; }}} printf ("%d\n", Dp[n][m]); }    return 0;} 
View Code

Zstu Learning algorithm 020--dp--queuing to buy tickets

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.