标签:sicily c++ iostream string vc
1011. Lenny‘s Lucky Lotto
|
Time Limit: 1sec Memory Limit:32MB
Description
Lenny likes to play the game of lotto. In the lotto game, he picks a list of N unique numbers in the range from 1 to M. If his list matches the list of numbers that are drawn, he wins the big prize.
Lenny has a scheme that he thinks is likely to be lucky. He likes to choose his list so that each number in it is at least twice as large as the one before it. So, for example, if N = 4 and M = 10, then the possible lucky lists Lenny could like are:
1 2 4 8 1 2 4 9 1 2 4 10 1 2 5 10 Thus Lenny has four lists from which to choose. Your job, given N and M, is to determine from how many lucky lists Lenny can choose. Input
There will be multiple cases to consider from input. The first input will be a number C (0 < C <= 50) indicating how many cases with which you will deal. Following this number will be pairs of integers giving values for N and M, in that order. You are
guaranteed that 1 <= N <= 10, 1 <= M <= 2000, and N <= M. Each N M pair will occur on a line of its own. N and M will be separated by a single space.
Output
For each case display a line containing the case number (starting with 1 and increasing sequentially), the input values for N and M, and the number of lucky lists meeting Lenny’s requirements. The desired format is illustrated in the sample shown below.
Sample Input
34 102 202 200 Sample Output
Case 1: n = 4, m = 10, # lists = 4Case 2: n = 2, m = 20, # lists = 100Case 3: n = 2, m = 200, # lists = 10000 // Problem#: 1011 // Submission#: 3731196 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include <cstdio> #include <memory.h> #define N 15 #define M 2012 unsigned long long dp[N][M]; int main(){ int c,t,i,j,k; int n,m; unsigned long long result=0; scanf("%d",&c); for (t=1;t<=c;t++) { scanf("%d%d",&n,&m); result=0; memset(dp,0,sizeof(dp)); for (i=1;i<=m;i++) dp[1][i]=1; for (i=2;i<=n;i++) { for (j=1;j<=m;j++) { for (k=i-1;k<=j/2;k++) dp[i][j]=dp[i][j]+dp[i-1][k]; } } for (i=n;i<=m;i++) result=result+dp[n][i]; printf("Case %d: n = %d, m = %d, # lists = %lld\n", t,n,m,result); } return 0; } |
Sicily 1011. Lenny's Lucky Lotto
标签:sicily c++ iostream string vc
原文地址:http://blog.csdn.net/christophe123/article/details/45843589