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;
    }
    
  • 相关阅读:
    We7网站群系统中标胜利油田项目 开源CMS
    We7荣获“政府网站群建设最佳产品奖” 开源CMS
    JAVA中 成员变量和和实例变量区别 前行
    HTTPS 加密原理探究 前行
    zip mysql安装启动方式 前行
    如何获取监听iframe src属性的变化进行后续操作 前行
    js分割url提取参数 前行
    web跨域问题解决方案 前行
    作业3.18
    3.26作业
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3226482.html
Copyright © 2011-2022 走看看