• soj1011. Lenny's Lucky 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

    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

    开个二维数组,动态规划,记住递推关系:f[i][x] = sum(f[i-1][j]) ,其中j = 1 to x/2
    代码如下:
     
    #include <iostream>
    #include <memory.h>
    using namespace std;
    //注意这里记得考虑精度问题,应选用unsigned long long,不然会WA
    unsigned long long qq[11][2001];
    
    int main()
    {
    	int num;
    	int count = 0;
    	cin >> num;
    	while(num--)
    	{
    		count++;
    		memset(qq,0,sizeof(qq));
    		int N,M;
    		cin >> N >> M;
    		int i,j,k;
    	    unsigned long long sum = 0;
    		for(i = 1;i <= M;i++)
    			qq[1][i] = 1;
    		for(i = 2;i <= N;i++)
    		{
    			for(j = 1;j <= M;j++)
    			{
    				for(k = 1;k <= j / 2;k++)
    					qq[i][j] += qq[i-1][k];
    			}
    		}
    		for(i = 1;i <= M;i++)
    			sum += qq[N][i];
    		cout << "Case " << count << ": n = " << N << ", m = " << M << ", # lists = " << sum << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    tomcat9部署到nginx,不能通过nginx访问到tomcat
    解决Linux系统部署webapp,JavaMail 发送邮件javax.mail.MessagingException: 501 Syntax: HELO hostname问题
    先本地仓库中国添加jar包
    IDEA修改pom.xml文件不自动下载的问题
    JavaWeb路径的理解【加不加斜杠又何区别】
    IDEA好用的模板设置
    使用maven启动web项目报错
    MAVEN的学习(图片资源来自黑马程序员)
    option标签不支持单击事件
    immutable.js学习笔记(九)----- Range 与 Repeat
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3226482.html
Copyright © 2020-2023  润新知