Sicily 1011. Lenny's Lucky Lotto
来源:互联网 发布:软件测试工程师培训班 编辑:程序博客网 时间:2024/05/20 01:34
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 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#: 2216249// 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 <stdio.h>#include <math.h>#include <stdlib.h>#include <string.h>long long buf[11][2001];long long num(int a, int b){ //printf("request:%d %d\n", a, b); int mi = 1; for(int i = 1; i < a; i++) { mi *= 2; } if(b < mi) { buf[a][b] = 0; return 0; } if(a == 1) { return 1; } if(a == 2 && b == 2) { return 1; } if(a == 2 && b == 3) { return 1; } if(buf[a][b] != 0) { return buf[a][b]; } long long sum = 0; for(int i = b / 2; i >= mi / 2; i--) { sum += num(a - 1, i); } buf[a][b] = sum; return sum;}long long sum(int a, int b){ int mi = 1; int i; for(i = 1; i < a; i++) { mi *= 2; } long long s = 0; for(i = b; i >= mi; i--) { //printf("request:%d %d\n", a, i); s += num(a, i); } return s;} int main(){ int k; int a; int b; int n; scanf("%d", &n); memset(buf, 0, sizeof(buf)); for(k = 0; k < n; k++) { scanf("%d %d", &a, &b); printf("Case %d: n = %d, m = %d, # lists = %lld\n", k + 1, a, b, sum(a, b)); } }
- [sicily online]1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- Sicily 1011.Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- Sicily 1011 Lenny's Lucky Lotto
- 1011. Lenny's Lucky Lotto
- Scily 1011. Lenny's Lucky Lotto
- Scily 1011. Lenny's Lucky Lotto
- pku2193 Lenny's Lucky Lotto Lists
- poj 2193 Lenny's Lucky Lotto Lists
- zoj 2402 - Lenny's Lucky Lotto Lists
- POJ 2193 Lenny's Lucky Lotto Lists
- zoj 2402 Lenny's Lucky Lotto Lists
- ZOJ 2402 Lenny's Lucky Lotto Lists(简单DP)
- 给Git或者APT设置代理
- MySQL Server Error Codes and Messages
- 盗QQ与反盗
- 深入理解HTTP Session
- Cow Patterns poj 3167 (hash解法)
- Sicily 1011. Lenny's Lucky Lotto
- 创建一个jQuery UI的垂直进度条效果
- 我的中科院之旅
- uva11991
- 数据循环移位
- C++解析得到的JSON数据
- 一个应届计算机毕业生的2012求职之路
- Android学习小应用案例---根据身高和性别计算标准体重
- postgreSQL在debian下安装、使用(SIL4—linux学习篇)