sicily 1011. Lenny's Lucky Lotto

本文探讨了在幸运数字选号游戏中,如何通过算法计算选择特定规律数字组合的概率,适用于Lotto等彩票游戏。
部署运行你感兴趣的模型镜像

1011. Lenny's Lucky Lotto

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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 = 4 and = 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

//a[i][j] += a[i - 1][k] i表示第几个,j表示这个数是多少
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	int T;
	cin >> T;
	for (int index = 1; index <= T; index++)
	{
		int n, m;
		cin >> n >> m;

		int a[20][3001];
		memset(a, 0, sizeof(a));
		for (int i = 1; i <= m; i++)
			a[1][i] = 1;
		for (int i = 2; i <= n; i++)
			for (int k = 1; k <= m; k++)
				for (int j = 2 * k; j <= m; j++)
					a[i][j] += a[i - 1][k];
		long int sum = 0;
		for (int i = 1; i <= m; i++)
			sum += a[n][i];
		cout << "Case " << index << ": n = " << n << ", m = " << m << ", "
			 << "# lists = " << sum << endl;
	}
}

// 下面这种可以将各种方案输出来,但是范围不能太大,容易超时

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
vector<int> v;
int c = 0;
int n, m;
void dps(int f, int m, int count)
{
	if (count == n) {
		c++;
		for (int i = 0; i < v.size(); i++)
			cout << v[i] << " ";
		cout << endl;
		return;
	}
	int p = m/(pow(2, n - count - 1)); // 每个位置能取的上限
	for (int t1 = f; t1 <= p; t1++)
	{
		count++;
		v.push_back(t1);
		dps( 2 * t1, m, count);
		count--;
		v.pop_back();
	}

}


您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值