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 = 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
// 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));    }    }                                 


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 高中的会考没过怎么办 毕业证和学位证丢了怎么办 大学毕业证学位证丢了怎么办 大学毕业证和学位证丢了怎么办 毕业证是士官证号码怎么办 自考本科准考证丢了怎么办 自考档案搞丢了怎么办 自考本科档案在自己手里怎么办? 本科自考准考证丢了怎么办 大学团员证丢了怎么办 大学开学团员证丢了怎么办 研究生开学没有团员证怎么办 研究生开学已经不是团员了怎么办 毕业了要搬宿舍怎么办 中专学历认证已停止怎么办 中专不做学历认证考试怎么办 大学生欠学费被扣毕业证怎么办 考警校体检没过怎么办 美国签证申请预约名字写错怎么办 当兵不从学校走怎么办 门牙崩了一小块怎么办 遇到很难过的事情怎么办 小孩子上课精力不集中怎么办 每天工作都很累压力大怎么办 重体力活搬不动怎么办 大学没参加体测怎么办 英文写的很丑怎么办 患有勃起障碍应该怎么办较好 运动过度小腿肌肉酸痛怎么办 高考有纹身是字怎么办 新生儿测听力没过关怎么办 色弱高考体检时没查出来怎么办 公司福利体检查二对半怎么办 高考体检表复印件丢了怎么办 高考体检表身高填错了怎么办 大学档案高考体检表丢了怎么办 工厂组织体检我有乙肝怎么办 我有乙肝单位组织体检怎么办? 矮腰袜子老掉怎么办 短腰袜子老下滑怎么办 中考体检结果丢了怎么办