Problem link-

GNYR04C - Lennys Lucky Lotto Lists


Lotto is a lottery, typically with an accumulating jackpot, in which participants play numbers of their choice in a random drawing. Lenny likes to play the lotto in Lincoln county Louisiana. In the game, he picks a list of n numbers in the range from 1 to m. If his list matches the drawn list, he wins the big prize, a lifetime supply of large lemons.

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 pick are:

    1 2 4 8
    1 2 4 9
    1 2 4 10
    1 2 5 10

Thus Lenny has 4 lists to choose from.

Your job, given n and m, is to count how many lucky lists Lenny has to his disposal.


The first line of input is a single non-negative integer, which is the number of data sets to follow. All data sets should be handled identically. The next lines, one per data set, contain two integers, nand m. It is guaranteed that 1 <= n <= 10 and 1 <= m <= 2000 and n <= m.


For each data set, print a line like the following:

Data set in m number

where i is the data set number (beginning with 1), and number is the maximum number of lucky lists corresponding to the provided values of n and m.


4 10

Data set 1: 4 10 4


Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD                 1000000007LL
#define EPS                 1e-9
#define io                  ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAXN = 1e5+5;

ll dp[11][2001];

ll solve(int n, int m){
	// cout << numbers << " " << curr << endl;
	if(n == 0)	return 1LL;
	if(m == 0)	return 0LL;
	if(dp[n][m] != -1)	return dp[n][m];
	ll res = 0;
	res += solve(n, m - 1);
	res += solve(n-1, m / 2);
	return dp[n][m] = res;

int main(){
	// io;
	int kase;
	scanf("%d", &kase);
	for(int i = 1; i <= kase; i++){
		int n, m;
		memset(dp, -1, sizeof dp);
		scanf("%d%d", &n, &m);
		printf("Data set %d: %d %d %lld\n", i, n, m, solve(n, m));
	return 0;
Copy The Code & Try With Live Editor


4 10


Data set 1: 4 10 4


SPOJ Solution- Lennys Lucky Lotto Lists-Solution in C, C++, Java, Python

SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python