zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    leetcode Power of Two
    leetcode Merge Two Sorted Lists
    Mac linux 安装memcached服务 用法
    Vsftp配置都没有问题 连接不上 530 Login incorrect 解决方法
    mysql 远程连接不上 %用户已经添加了
    Centos yum 安装mysql报错 No package mysql-server available.
    Linux 查询程序安装路径 是否安装
    php报错 Call to undefined function mb_stripos()
    mac编译openssl扩展报错 openssl.c:44:10: fatal error: 'openssl/evp.h' file not found
    在安装mysqli的时候,出现error: ext/mysqlnd/mysql_float_to_double.h: No such file or direc
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3226482.html
Copyright © 2011-2022 走看看