文章标题
来源:互联网 发布:中国制造业出口数据 编辑:程序博客网 时间:2024/06/09 17:33
- Lenny’s Lucky Lotto
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
Copy sample input to clipboard
3
4 10
2 20
2 200
Sample Output
Case 1: n = 4, m = 10, # lists = 4
Case 2: n = 2, m = 20, # lists = 100
Case 3: n = 2, m = 200, # lists = 10000
#include <iostream>#include <cstring>#include <cmath>using namespace std;int main(int argc, char **argv){ int cases; int N, M; cin >> cases; long long arr[11][3000]; int k; for (k = 1; k <= cases; k++) { cin >> N >> M; memset(arr, 0, sizeof(arr)); int i , j; for (i = 1; i <= M; i++) { arr[1][i] = 1; } for (i = 2; i <= N; i++) { for (j = 1; j <= M; j++) { if (j % 2 == 0) arr[i][j] = arr[i][j-1] + arr[i-1][j/2]; else arr[i][j] = arr[i][j-1]; } } long long sum = 0; for (i = 1; i <= M; i++) { sum += arr[N][i]; } cout << "Case " << k << ": n = " << N << ", m = " << M << ", # lists = " << sum << endl; } return 0;}
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 最完美解决Nginx部署ThinkPHP项目的办法
- MarkDown 语法
- JavaScript斐波纳契数列非递归算法
- 腾讯IEG面试失败经验总结
- C 源码学习——memcpy函数
- 文章标题
- Git 添加远程库
- IOS面试题汇总(中英文)
- OC学习笔记-Foundation框架(一)
- IOS Android 手机助手原理以及源码(iTunes.dll iTunesCore.dll 作用)
- win8搜索不到wifi怎么办?windows8搜索不到无线网络解决方法图解
- Git 从远程库克隆
- waitpid(or wait)和SIGCHILD的关系 http://blog.csdn.net/liuxingen/article/details/38350347
- Arcpy基础入门-6、arcpy要素属性操作