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